Microsoft KB Archive/316321

= BUG: The SqlConnection object presents misleading user interface for the ConnectionString property =

Article ID: 316321

Article Last Modified on 5/13/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft ADO.NET 1.1
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition

-



This article was previously published under Q316321



This article refers to the following Microsoft .NET Framework Class Library namespaces:
 * System.Data
 * System.Data.OleDb
 * System.Data.SqlClient



SYMPTOMS
When you try to set the ConnectionString property for a SqlConnection object at design time, the OLEDB DataLinks dialog box permits you to select any OLE DB provider on your system to generate a connection string for the SqlConnection object. When you try to run the application, however, you may receive an error depending on which provider you have selected.

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.



CAUSE
The SqlConnection object is used only for connecting to SQL Server.



RESOLUTION
If you want to connect to other data providers, use the OledbConnection or OdbcConnection object.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Start Visual Studio .NET. Create a new Windows Application in Visual Basic .NET. Form1 is added to the project by default. Make sure that your project contains a reference to the System.Data namespace. Place a Command button on Form1. Change the Name property of the button to btnTest, and then change the Text property to Test .  Use the Imports statement on the System and System.Data namespaces so that you are not required to qualify declarations in those namespaces later in your code. Add this code to the &quot;General Declarations&quot; section of Form1: Imports System Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient </li> Drag a SqlConnection object to the form.</li> In the Properties window, select New Connection for the ConnectionString property.</li> In the Data Link Properties window, click the Provider tab, select Micrososft Jet 4.0 OLE DB Provider, and then click Next.</li> Select a sample Access database and then click OK.</li>  Paste the following code in the btnTest Click event: Dim da = New SqlDataAdapter(&quot;SELECT * FROM Customers&quot;, SqlConnection1) Dim ds As New DataSet da.Fill(ds, &quot;Customers&quot;) MessageBox.Show(&quot;Connected Successfully&quot;) </li> Save your project. On the Debug menu, click Start to run your project.</li> Click Test. The code fails with the exception mentioned in the &quot;Symptoms&quot; section of this article.</li> Change the ConnectionString as necessary for your environment, and then save and run your project.</li> Click Test. The connection is made successfully.</li></ol>

<div class="references_section">