<?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: Create Database Connection Error in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441692#M69002</link>
    <description>&lt;P&gt;I suggest that, in the future, you first connect interactively to prove that a connection is possible. An added benefit is that JMP will write a Source table script with the correct JSL for the same result. You can copy this script to your own instead of writing and debugging your own,&lt;/P&gt;</description>
    <pubDate>Thu, 02 Dec 2021 15:05:09 GMT</pubDate>
    <dc:creator>Mark_Bailey</dc:creator>
    <dc:date>2021-12-02T15:05:09Z</dc:date>
    <item>
      <title>Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441513#M68974</link>
      <description>&lt;P&gt;I'm trying to establish connection to database through scripting and it's the first time I'm doing this. I was able to create the following script but it seems that there's a bug that everytime there's unsuccessful connection, there's a default "JMP Alert" pop-up (see snapshot) instead of being contained within the "Try" function (I was trying with an incorrect database name of "TEST" which led to the pop-up. Is there a way to control this ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally, are there any good reading material (e.g. basic best practice) for incorporating SQL to JMP script ?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;names default to here(1);

//Standard SQL syntax string to create database connection from JMP
DB.SQL = "DSN="||"DSN_Name" ||";Description=" || "DSN_Desc" || ";
	Trusted_Connection=Yes;APP=JMP;DATABASE="|| "DB_Name" || ";";

//Expression to arrange the User Interface of PODS setup
//Require users to input Database Source Name (DSN Name), Database Source Description (DSN Description) and Database Name 
DB_Connection.UI = expr(
	Hlistbox(spacerbox(size(5,5)),
		Vlistbox(align("right"),spacerbox(size(5,5)),
			vb1_1 = vlistbox(align("left"),
				panelbox("Insert PODS Connection Info",
					lineupbox(ncol(2),
						Textbox("DSN Name : "),TEB_DSN_Name = Texteditbox("",set width(150)),
						Textbox("DSN Description : "),TEB_DSN_Desc = Texteditbox("",set width(150)),
						Textbox("Database Name : "),TEB_DB_Name = Texteditbox("",set width(150))
					)
				),
				spacerbox(size(5,5)),
				temp1_1 = Textbox("PODS Connection Status: ")
			),
			spacerbox(size(3,3)),
			Test_DB_Connection.button,
			spacerbox(size(3,3)),
			button box("           Cancel          ",currentwindow()&amp;lt;&amp;lt;close window)
		)
	)
);

//Expression to set up "Set Connection" button
//Takes input values, substitute Standard SQL syntax DB.SQL with input values and execute open connection command
//Flag out "Successful" or "Unsuccessful" as results
Test_DB_Connection.button = expr(
	button box("   Set Connection   ",
		Input.DSN_Name = TEB_DSN_Name &amp;lt;&amp;lt; Get Text();
		Input.DSN_Desc = TEB_DSN_Desc &amp;lt;&amp;lt; Get Text();
		Input.DB_Name = TEB_DB_Name &amp;lt;&amp;lt; Get Text();
		
		DB.SQL_Updated = Substitute(DB.SQL,"DSN_Name",Input.DSN_Name,"DSN_Desc",Input.DSN_Desc,"DB_Name",Input.DB_Name);
		try(db = Create database connection (DB.SQL_Updated),
			print("Unable to connect to Database")
		);
		try(db &amp;lt;&amp;lt; get type;
			try(temp1_1 &amp;lt;&amp;lt; delete);
			temp1_1 = hlistbox(
				Textbox("PODS Connection Status: "),
				Textbox("Successful", &amp;lt;&amp;lt; font color(4)) 
			);
			vb1_1 &amp;lt;&amp;lt; append (temp1_1);
			,
			
			try(temp1_1 &amp;lt;&amp;lt; delete);
			temp1_1 = hlistbox(
				Textbox("PODS Connection Status: "),
				Textbox("Unsuccessful", &amp;lt;&amp;lt; font color(3)) 
			);
			vb1_1 &amp;lt;&amp;lt; append (temp1_1);
			,
		);
	)
);


nw1 = new window("PODS Connection Setup",
	showtoolbars(0), showmenu(0),
	DB_Connection.UI;
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Djtjhin_0-1638422324711.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/38088i8C678B4709313FDA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Djtjhin_0-1638422324711.png" alt="Djtjhin_0-1638422324711.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:06:28 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441513#M68974</guid>
      <dc:creator>Djtjhin</dc:creator>
      <dc:date>2023-06-09T18:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441600#M68985</link>
      <description>&lt;P&gt;Try some variation of this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;bi = Batch Interactive( 1 );
Try(
    db = Create Database Connection( DB.SQL_Updated );
    If( Is Missing( db ),
        Print( "unable..." ) // I think this is the right way to notice the error
    );
,
    Print( "Unable to connect to Database" ) // I think this may not happen?
);
Batch Interactive( bi );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use logcapture() if the log message is an issue.&lt;/P&gt;
&lt;P&gt;I think using the returned value from the first batchinteractive call to pass to the second is the right way to push/pop the flag. I think JMP is internally pushing "interactive" for the flag when a script is run from a button.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.jmp.com/t5/Discussions/Open-Excel-within-a-button-box-Strange-behavior/m-p/385813/highlight/true#M63594" target="_self"&gt;Note&lt;/A&gt; from &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5579"&gt;@Wendy_Murphrey&lt;/a&gt; . Searching the community will produce more history about batch interactive.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 09:52:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441600#M68985</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-12-02T09:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441601#M68986</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/982"&gt;@Craige_Hales&lt;/a&gt;. I don't understand what exactly "Batch Interactive ()" does, but it solves the issue. :D&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 10:19:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441601#M68986</guid>
      <dc:creator>Djtjhin</dc:creator>
      <dc:date>2021-12-02T10:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441656#M68995</link>
      <description>&lt;P&gt;Ah, sorry, left that out. If JMP believes it is running in Batch mode (ancient terminology about batch processing data, without a terminal for user input) then those alerts are written to the log and a default response is made. Otherwise, in Interactive mode, JMP opens a modal dialog to get the response. Most of the time, if a button was pressed to start some JSL, the interactive behavior is correct. And if a script is submitted (over lunch perhaps) you'd rather not come back to an "ok?" dialog. Button scripts tend to be short, so the heuristic tends to work.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 12:47:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441656#M68995</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2021-12-02T12:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441692#M69002</link>
      <description>&lt;P&gt;I suggest that, in the future, you first connect interactively to prove that a connection is possible. An added benefit is that JMP will write a Source table script with the correct JSL for the same result. You can copy this script to your own instead of writing and debugging your own,&lt;/P&gt;</description>
      <pubDate>Thu, 02 Dec 2021 15:05:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441692#M69002</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2021-12-02T15:05:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create Database Connection Error</title>
      <link>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441828#M69012</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5358"&gt;@Mark_Bailey&lt;/a&gt;. Yep, you're right. Definitely a good starting point to leverage the Source table script. I was exploring other ways as I might need to expand the usage of this script to other potential users within my organizations which may not be as familiar with JMP, let alone scripting. Thanks for the advise :)&lt;/img&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 00:59:50 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Create-Database-Connection-Error/m-p/441828#M69012</guid>
      <dc:creator>Djtjhin</dc:creator>
      <dc:date>2021-12-03T00:59:50Z</dc:date>
    </item>
  </channel>
</rss>

