BUG: The SqlConnection object presents misleading user interface for the ConnectionString property (316321)



The information in this article applies to:

  • Microsoft ADO.NET (included with the .NET Framework)
  • Microsoft ADO.NET (included with the .NET Framework 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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Visual Studio .NET.
  2. Create a new Windows Application in Visual Basic .NET. Form1 is added to the project by default.
  3. Make sure that your project contains a reference to the System.Data namespace.
  4. Place a Command button on Form1. Change the Name property of the button to btnTest, and then change the Text property to Test.
  5. 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 "General Declarations" section of Form1:
    Imports System
    Imports System.Data
    Imports System.Data.OleDb
    Imports System.Data.SqlClient
    					
  6. Drag a SqlConnection object to the form.
  7. In the Properties window, select New Connection for the ConnectionString property.
  8. In the Data Link Properties window, click the Provider tab, select Micrososft Jet 4.0 OLE DB Provider, and then click Next.
  9. Select a sample Access database and then click OK.
  10. Paste the following code in the btnTest Click event:
        Dim da = New SqlDataAdapter("SELECT * FROM Customers", SqlConnection1)
        Dim ds As New DataSet()
        da.Fill(ds, "Customers")
        MessageBox.Show("Connected Successfully")
    					
  11. Save your project. On the Debug menu, click Start to run your project.
  12. Click Test. The code fails with the exception mentioned in the "Symptoms" section of this article.
  13. Change the ConnectionString as necessary for your environment, and then save and run your project.
  14. Click Test. The connection is made successfully.

REFERENCES

For more information about ADO.NET objects and syntax, see the following topic in the Microsoft .NET Framework Software Development Kit (SDK) documentation or MSDN Online: For more information about .NET Managed Providers, see the .NET Developer's Center or the following Microsoft Web site:

Modification Type:MinorLast Reviewed:3/9/2006
Keywords:kbvs2002sp1sweep kbbug kbnofix kbSqlClient kbSystemData KB316321