<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>James Wiseman &#187; Database Connection</title>
	<atom:link href="http://www.jameswiseman.com/blog/tag/database-connection/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jameswiseman.com/blog</link>
	<description>My Programming Notebook and Other Things</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:41:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Setting Default SQL Server Database Using ISQL</title>
		<link>http://www.jameswiseman.com/blog/2011/05/10/setting-default-sql-server-database-using-isql/</link>
		<comments>http://www.jameswiseman.com/blog/2011/05/10/setting-default-sql-server-database-using-isql/#comments</comments>
		<pubDate>Tue, 10 May 2011 18:55:13 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Command Line]]></category>
		<category><![CDATA[Database Connection]]></category>
		<category><![CDATA[ISQL]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=2946</guid>
		<description><![CDATA[You might be familiar with the following scenario: You have a SQL Server database server hosting more than one database, but you just so happen to be accessing one in particular from your development environment (Query Analyser, Management Studio, etc). So, you run a little query to automatically connect you to this database when you [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><div class="zemanta-img zemanta-action-dragged" style="margin: 1em; display: block;">
<div class="wp-caption alignright" style="width: 250px"><a href="http://www.flickr.com/photos/36724437@N03/4297955162"><img title="Problems????" src="http://www.jameswiseman.com/blog/wp-content/uploads/2011/05/4297955162_3dcbd7344c_m1.jpg" alt="Problems????" width="240" height="167" /></a><p class="wp-caption-text">Image by essecento via Flickr</p></div>
</div>
<p>You might be familiar with the following scenario:</p>
<p>You have a SQL Server database server hosting more than one database, but you just so happen to be accessing one in particular from your development environment (Query Analyser, Management Studio, etc).</p>
<p>So, you run a little query to automatically connect you to this database when you connect to the server. You might try something like:</p>
<pre name="code" class="SQL">Exec sp_defaultdb @loginame='DOMAIN\UsrNam', @defdb='SomeDatabase';</pre>
<p>So, now when you log on, your database is ready and waiting to be used without having to manually select it. I have found this scenario common in development environments, when you are typically running lots of ad-hoc SQL queries, or running in code (stored procedures, views, triggers, etc) against the database.</p>
<p>However if you are working on different databases on the same server, defaulting to a particular one can cause you problems if you need to run in code against a different database. On occasions I have applied stored procedures to the default database, when I meant to do it against another one on the server!</p>
<p>Another consequence is when a development database is refreshed or rebuilt from some external source (from a live environment, for example). Although your default database may exist by name, this is not enough for SQL Server, which fails to log you on and gives the error message:</p>
<blockquote><p><em>Cannot open user default database.</em></p></blockquote>
<p>You will also get this if you have chosen to rename the database.</p>
<p>So what to do in this instance?</p>
<p>Well, we can defer to the trusty <a title="isql Utility" href="http://msdn.microsoft.com/en-us/library/aa214007(v=sql.80).aspx" target="_blank">ISQL command line utility</a>, as shown in the following screenshot:</p>
<p><a href="http://www.jameswiseman.com/blog/wp-content/uploads/2011/05/ISQL_CommandLine_SetDefaultDB.png"><img class="size-full wp-image-2949 alignnone" title="ISQL_CommandLine_SetDefaultDB" src="http://www.jameswiseman.com/blog/wp-content/uploads/2011/05/ISQL_CommandLine_SetDefaultDB.png" alt="" width="669" height="530" /></a></p>
<p>Simply follow these steps:</p>
<ol>
<li>Open a DOS  command Prompt</li>
<li>Open up an <strong>ISQL</strong> Session. I used the following command:
<ul>
<li>-S SQLServer_Name &#8211; Specify the name of the SQL Server to which you are connecting.</li>
<li>-E &#8211; Stipulate to connect as a trusted connection (Windows Authentication)</li>
<li>-d master &#8211; The database name to which you are going to connect. Here I specified &#8216;master&#8217;</li>
</ul>
</li>
<p>isql -S SQLServer_Name -E -d master</p>
<p>The three options user above are as follows:</p>
<p>Of course, you can connect however you want. For more options (also shown in the screenshot above), type in<strong> isql /?</strong> for a full list, or refer to the site on the above link.</p>
<li>Now run a version of the above script, setting the default database to master</li>
<pre name="code" class="SQL">Exec sp_defaultdb @loginame='DOMAIN\UsrNam', @defdb='master';</pre>
<li>To apply this, enter &#8216;GO&#8217; on the next line.</li>
</ol>
<p>This will ensure your SQL Server defaults you to the &#8216;master&#8217; database in all subsequent connections (unless you change them again). I would counsel this as general good practice, and it comes recommended by a friendly DBA I happen to know.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://img.zemanta.com/pixy.gif?x-id=2ce7669a-79d0-41e5-8855-def20914561c" alt="" /></div>
<div class="shr-publisher-2946"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fwww.jameswiseman.com%2Fblog%2F2011%2F05%2F10%2Fsetting-default-sql-server-database-using-isql%2F' data-shr_title='Setting+Default+SQL+Server+Database+Using+ISQL'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.jameswiseman.com%2Fblog%2F2011%2F05%2F10%2Fsetting-default-sql-server-database-using-isql%2F' data-shr_title='Setting+Default+SQL+Server+Database+Using+ISQL'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2011/05/10/setting-default-sql-server-database-using-isql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Universal Data Link (.udl) Files and Conection Testing</title>
		<link>http://www.jameswiseman.com/blog/2010/07/13/windows-universal-data-link-udl-files-and-conection-testing/</link>
		<comments>http://www.jameswiseman.com/blog/2010/07/13/windows-universal-data-link-udl-files-and-conection-testing/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 12:17:47 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Database Access]]></category>
		<category><![CDATA[Database Connection]]></category>
		<category><![CDATA[UDL File]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=1084</guid>
		<description><![CDATA[Ever wanted to an Ad-Hoc database connection test that you can perform wherever you are on whatever computer you happen to be logged onto (security permissions permitting)? Well, you can ﻿use a Windows Universal Data Link (.udl) File. This Microsoft post gives details on how to create and configure a UDL file for use. We are [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Ever wanted to an Ad-Hoc database connection test that you can perform wherever you are on whatever computer you happen to be logged onto (security permissions permitting)?</p>
<p>Well, you can ﻿use a Windows Universal Data Link (.udl) File. <a title="Microsoft UDL File" href="http://msdn.microsoft.com/en-us/library/e38h511e(VS.71).aspx" target="_blank">This Microsoft post</a> gives details on how to create and configure a UDL file for use.</p>
<p>We are just creating it to test a connection, so we can follow the Microsoft steps:</p>
<ol type="1">
<li>Open Windows Explorer. (Although, your desktop will do).</li>
<li>Select the folder in which you want to store the .udl file. (Again, the desktop is fine for this).</li>
<li>Create a new Text Document file. A new file named New Text Document.txt appears in the directory. Rename this file, removing all spaces and changing its file
<p><a href="http://www.jameswiseman.com/blog/wp-content/uploads/2010/07/udl-file-icon.jpg"><img class="size-full wp-image-1085 alignright" title="udl-file-icon" src="http://www.jameswiseman.com/blog/wp-content/uploads/2010/07/udl-file-icon.jpg" alt="" width="76" height="70" /></a></p>
<p>extension to .udl.</li>
</ol>
<p>Note A warning that changing file extensions can cause files to become unusable might appear. Disregard it.</p>
<p>If you are running Windows 98 and Windows NT systems with Microsoft Data Access Components (MDAC) installed, right-click the right pane, or results pane, select New, and choose Microsoft Data Link. A new file named New Microsoft Data Link.udl appears in the directory. You can rename this file.</p>
<p><a href="http://www.jameswiseman.com/blog/wp-content/uploads/2010/07/udl-file-properties1.bmp"><img class="alignleft size-full wp-image-1117" title="udl-file-properties" src="http://www.jameswiseman.com/blog/wp-content/uploads/2010/07/udl-file-properties1.bmp" alt="" width="183" height="263" /></a>Next, right-click the new file and select <strong>Properties</strong>. A dialog similar to the one in the adjacent figure appears.  Specify your provider on the <strong>Provider</strong> tab and then enter the connection information on the <strong>Connection</strong> tab.</p>
<p>Clicking &#8216;Test Connection&#8217; will perform you desired test.</p>
<div class="shr-publisher-1084"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fwww.jameswiseman.com%2Fblog%2F2010%2F07%2F13%2Fwindows-universal-data-link-udl-files-and-conection-testing%2F' data-shr_title='Windows+Universal+Data+Link+%28.udl%29+Files+and+Conection+Testing'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fwww.jameswiseman.com%2Fblog%2F2010%2F07%2F13%2Fwindows-universal-data-link-udl-files-and-conection-testing%2F' data-shr_title='Windows+Universal+Data+Link+%28.udl%29+Files+and+Conection+Testing'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2010/07/13/windows-universal-data-link-udl-files-and-conection-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	<img style='margin:0;padding:0;border:0;' width='1px' height='1px' src="http://www.jameswiseman.com/blog/wp-content/plugins/mystat/mystat.php?act=time_load&id=623696&rnd=1370217765" /></channel>
</rss>

