<?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 Disconnect from a database via script? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/597791#M80130</link>
    <description>&lt;P&gt;The key is in naming the database connection separately from the query. In your example above, RedBinMain is for the query, not the connection. Example below that should make the previous sentence actually make sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dbc = Create Database Connection(
	"ODBC:DSN=Excel 12.0;DBQ=I:\Engineering\Data\JMPTempData\redbindownload_JMPTMP.xlsx;DefaultDir=I:\Engineering\Data\JMPTempData;DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;"
);

//your script here: RedBinMain = New SQL Query ........ &amp;lt;&amp;lt; Run Foreground

Close Database Connection (dbc);


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Feb 2023 21:28:30 GMT</pubDate>
    <dc:creator>Jed_Campbell</dc:creator>
    <dc:date>2023-02-06T21:28:30Z</dc:date>
    <item>
      <title>How to Disconnect from a database via script?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/597749#M80126</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am using the File&amp;gt;Database&amp;gt;Query Builder method to connect to an excel file and create a table. I am able to close the table with jmp script but the connection remains active and locks up the excel file for other users. How can I disconnect via jmp script? I can manually go through&amp;nbsp;File&amp;gt;Database&amp;gt;Open&amp;gt;Disconnect but I would like to do this automatically in the running script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the query code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;RedBinMain = New SQL Query(
	Version( 130 ),
	Connection(
		"ODBC:DSN=Excel 12.0;DBQ=I:\Engineering\Data\JMPTempData\redbindownload_JMPTMP.xlsx;DefaultDir=I:\Engineering\Data\JMPTempData;DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;"
	),
	QueryName( "RedBinMain_beta" ),
	Select(
		Column( "RBNbr", "t1" ),
		Column( "DMR", "t1" ),
		Column( "Date_Entered", "t1" ),
		Column( "Initiator", "t1" ),
		Column( "Location", "t1" ),
		Column( "AssignedPerson", "t1" ),
		Column( "Problem", "t1" ),
		Column( "USI_PN", "t1" ),
		Column( "Customer", "t1" ),
		Column( "Disposition", "t1" ),
		Column( "LastUpdatedDate", "t1" ),
		Column( "Cause", "t1" ),
		Column( "Classification", "t1" ),
		Column( "Defect_Code", "t1" ),
		Column( "BrokenSubMenu", "t1"),
		Column( "BrokenSubMenu_1", "t1"),
		Column( "Dimensional_Code", "t1" ),
		Column( "Notes", "t1" ),
		Column( "Assignable_WorkCell", "t1" ),
		Column( "DispositionerInvestigator", "t1" ),
		Column( "ScrappedQuantity", "t1" ),
		Column( "PreEtch", "t1" ),
		Column( "PostEtch", "t1" )
	),
	From( Table( "RedBinMain_beta", Alias( "t1" ) ) )
) &amp;lt;&amp;lt; Run Foreground;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried the below code with no luck&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;close database connection(RedBinMain);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What am I missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is where the connection is shown as "connected" using the ODBC driver "Excel 12.0"&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 200px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/49869iB491D8CB69D95A5F/image-size/small?v=v2&amp;amp;px=200" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2023 16:38:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/597749#M80126</guid>
      <dc:creator>MBRackliffe</dc:creator>
      <dc:date>2023-06-08T16:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to Disconnect from a database via script?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/597791#M80130</link>
      <description>&lt;P&gt;The key is in naming the database connection separately from the query. In your example above, RedBinMain is for the query, not the connection. Example below that should make the previous sentence actually make sense:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dbc = Create Database Connection(
	"ODBC:DSN=Excel 12.0;DBQ=I:\Engineering\Data\JMPTempData\redbindownload_JMPTMP.xlsx;DefaultDir=I:\Engineering\Data\JMPTempData;DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;"
);

//your script here: RedBinMain = New SQL Query ........ &amp;lt;&amp;lt; Run Foreground

Close Database Connection (dbc);


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2023 21:28:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/597791#M80130</guid>
      <dc:creator>Jed_Campbell</dc:creator>
      <dc:date>2023-02-06T21:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to Disconnect from a database via script?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/598033#M80165</link>
      <description>&lt;P&gt;Thank You! That makes sense and works now although I had a ODBC error at first until I removed the "ODBC:" before the DSN= statement.&lt;/P&gt;&lt;P&gt;I inserted "dbc" as the connection variable in the query as well in case anyone else reads this. Here is the new working code for reference.&lt;CODE class=" language-jsl"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dbc = Create Database Connection(
		"DSN=Excel 12.0;DBQ=I:\Engineering\Data\JMPTempData\redbindownload_JMPTMP.xlsx;DefaultDir=I:\Engineering\Data\JMPTempData;DriverId=1046;FIL=excel 12.0;MaxBufferSize=2048;PageTimeout=5;"
	);

RedBinMain = New SQL Query(
	Version( 130 ),
	Connection(dbc),
	QueryName( "RedBinMain_beta" ),
	Select(
		Column( "RBNbr", "t1" ),
		Column( "DMR", "t1" ),
		Column( "Date_Entered", "t1" ),
		Column( "Initiator", "t1" ),
		Column( "Location", "t1" ),
		Column( "AssignedPerson", "t1" ),
		Column( "Problem", "t1" ),
		Column( "USI_PN", "t1" ),
		Column( "Customer", "t1" ),
		Column( "Disposition", "t1" ),
		Column( "LastUpdatedDate", "t1" ),
		Column( "Cause", "t1" ),
		Column( "Classification", "t1" ),
		Column( "Defect_Code", "t1" ),
		Column( "BrokenSubMenu", "t1"),
		Column( "BrokenSubMenu_1", "t1"),
		Column( "Dimensional_Code", "t1" ),
		Column( "Notes", "t1" ),
		Column( "Assignable_WorkCell", "t1" ),
		Column( "DispositionerInvestigator", "t1" ),
		Column( "ScrappedQuantity", "t1" ),
		Column( "PreEtch", "t1" ),
		Column( "PostEtch", "t1" )
	),
	From( Table( "RedBinMain_beta", Alias( "t1" ) ) )
) &amp;lt;&amp;lt; Run Foreground;

Close Database Connection (dbc);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 15:18:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-Disconnect-from-a-database-via-script/m-p/598033#M80165</guid>
      <dc:creator>MBRackliffe</dc:creator>
      <dc:date>2023-02-07T15:18:25Z</dc:date>
    </item>
  </channel>
</rss>

