Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 316321 - Last Review: May 13, 2007 - Revision: 2.5
BUG: The SqlConnection object presents misleading user interface for the ConnectionString property
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
On This Page
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
- 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 "General
Declarations" section of Form1:
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
- Drag a SqlConnection object to the form.
- In the Properties window, select New Connection for the ConnectionString property.
- In the Data Link Properties window, click the Provider tab, select Micrososft Jet 4.0 OLE DB Provider, and then click Next.
- Select a sample Access database and then click OK.
- 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")
- Save your project. On the Debug menu, click Start to run your project.
- Click Test. The code fails with the exception mentioned in the "Symptoms"
section of this article.
- Change the ConnectionString as necessary for your environment, and then save and run your
project.
- 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:
APPLIES TO
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft ADO.NET 1.1
- Microsoft Visual Studio .NET 2002 Professional Edition
- Microsoft Visual Studio .NET 2003 Professional Edition
| kbvs2002sp1sweep kbbug kbnofix kbsqlclient kbsystemdata KB316321 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please