<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to create database connection reference to a SQL server? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265868#M51784</link>
    <description>&lt;P&gt;Hello pmroz,&lt;/P&gt;&lt;P&gt;thank you for your support! It works perfectly and it is much simpler. However, there was still problem with creating conn variable. What I did, I removed part &lt;STRONG&gt;UID=engineer&lt;/STRONG&gt; from the parameter chain, since I think the authentication is based on logging to the internal network and it remembers the previous user name settings. Additionally, I removed the name of the database at the end of the chain, since it is provided in the query. Best regards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;conn = Create Database Connection ("ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 May 2020 20:02:44 GMT</pubDate>
    <dc:creator>lukasz</dc:creator>
    <dc:date>2020-05-11T20:02:44Z</dc:date>
    <item>
      <title>How to create database connection reference to a SQL server?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265750#M51761</link>
      <description>&lt;P&gt;Hello Everybody,&lt;BR /&gt;I have an issue with creation of variable (or reference) after connecting to a database. I wanted to create variable &lt;STRONG&gt;conn&lt;/STRONG&gt; that I could use later to run different queries. At the beginning, however, I needed to create 2 connections since I needed data from different databases, but on the same SQL server (the same user name and password are required). For both connections I need to provide twice password for a given user name. I would like to provide it once and preferably during creation of the conn variable.&lt;BR /&gt;Later, I wanted to execute INSERT query to update only one cell by using conn variable created earlier and without any success. JMP log says that there was problem with establishing connection to database with "engineer" user name and indicates the line where I am creating conn variable:&lt;BR /&gt;&lt;STRONG&gt;[Microsoft][ODBC SQL Server Driver][SQL Server] Error during the login for the user "engineer".&lt;/STRONG&gt;&lt;BR /&gt;However, with the same user name I can successfully execute both "New SQL Queries" (after providing password for each query).&lt;BR /&gt;The evalinsert function seems to work as desired.&lt;/P&gt;&lt;P&gt;I would appreciate for hints how to solve the issue and indicating what I am missing. Best regards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;conn = Create Database Connection ("ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;UID=engineer;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;DATABASE=Data_1;");

Param_Data = New SQL Query(
	Version( 130 ),
	//conn; //providing connection reference here instead of Connection (below) returns an error	
	Connection(
		"ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;UID=engineer;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;DATABASE=Data_1;"
	),
	QueryName("Data1"),
	Select(
		Column( "Param1", "t1"),
		Column( "Param2", "t1"),
	),
	From( Table( "ParamData", Schema( "pi" ), Alias( "t1" ))),
);

Process_Data = New SQL Query(
	Version( 130 ),
	Connection(
		"ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;UID=engineer;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;DATABASE=Data_2;"
	),
	QueryName( "Data2" ),
	Select(
		Column( "Process1", "t2"),
		Column( "Process1", "t2"),
	),
	From( Table( "ProcessData", Schema( "dbo" ), Alias( "t2" ))),
);

//sql query
sql_update = evalinsert(
			"
			UPDATE pi.ParamData
			SET Param1 = '^combined_params^'
			WHERE Process1 = '^selected_process^'
			"				
);
write(sql_update);
execute sql (conn, sql_update);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 16:22:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265750#M51761</guid>
      <dc:creator>lukasz</dc:creator>
      <dc:date>2020-05-11T16:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to create database connection reference to a SQL server?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265855#M51782</link>
      <description>&lt;P&gt;It appears that the query builder uses it's own database connection.&amp;nbsp; This code using &lt;STRONG&gt;EXECUTE SQL&lt;/STRONG&gt; might be simpler, and only requires one connection to the database:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;conn = Create Database Connection ("ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;UID=engineer;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;DATABASE=Data_1;");

sql1 = 
"SELECT t1.Param1, t1.Param2
   FROM pi.ParamData t1";

param_data = execute sql(conn, sql1, "Data1");

sql2 = 
"SELECT t2.Process1, t2.Process2
   FROM dbo.ProcessData t2";

process_data = execute sql(conn, sql2, "Data2");

//sql query
// Need to load values in for combined_params and selected_process variables
sql_update = evalinsert(
			"
			UPDATE pi.ParamData
			SET Param1 = '^combined_params^'
			WHERE Process1 = '^selected_process^'
			"				
);
write(sql_update);
execute sql (conn, sql_update);

close database connection(conn);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 May 2020 18:02:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265855#M51782</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2020-05-11T18:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to create database connection reference to a SQL server?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265868#M51784</link>
      <description>&lt;P&gt;Hello pmroz,&lt;/P&gt;&lt;P&gt;thank you for your support! It works perfectly and it is much simpler. However, there was still problem with creating conn variable. What I did, I removed part &lt;STRONG&gt;UID=engineer&lt;/STRONG&gt; from the parameter chain, since I think the authentication is based on logging to the internal network and it remembers the previous user name settings. Additionally, I removed the name of the database at the end of the chain, since it is provided in the query. Best regards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;conn = Create Database Connection ("ODBC:Description=Server_Database;DRIVER=SQL Server;SERVER=Server;PWD=%_PWD_%;APP=JMP;WSID=DDPC0283;");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 20:02:44 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-create-database-connection-reference-to-a-SQL-server/m-p/265868#M51784</guid>
      <dc:creator>lukasz</dc:creator>
      <dc:date>2020-05-11T20:02:44Z</dc:date>
    </item>
  </channel>
</rss>

