Friday, February 10, 2012

Connecting to SQL Server 2005 from Visual C# 2005 Express Edition

I had SQL Server Express Edition installed. I then uninstalled both it and Visual C#. I then installed SQL Server 2005 Developer's Edition and reinstalled Visual C# -- both on the same machine. I can connect to SQL Server 2005 using SQL Server Management Studio. However, Visual C# is a different story. When I try to add a new Data Connection, it defaults the data source to .\SQLEXPRESS, which is no longer on my machine. I can select .\MSSQLSERVER, but when I click on either OK or Test Connection, I time out with an error message -- error 25 - Connection string is not valid. The connection string that is shown at the bottom of the Advanced dialog box is -- Data Source=.\MSSQLSERVER;AttachDbFilename=E:\Inventory\Data\Inventory_Data.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True

When connect to default instance, you cannot use .\MSSQLSERVER. Please try just "."

i.e. Data Source=.;AttachDbFilename=....blahblah.

|||The 'Add New Connection' dialog box doesn't give that option. It is a dropdown combo box, with the only option being '.\MSSQLSERVER'. It can't be edited. The dialog box is creating the connection string, not me.|||I just checked, and it seems it's a bug in VS 2005. Here is a workaround.
When you are in Add Connection window, change your data source from "Microsoft SQL Server Database File (SqlClient)" to "Microsoft SQL Server (SqlClient)". You can then input your server name as "." in the new window. You can also attach your database file.|||

Yet another workaround.

VS 2005, Tools Menu --> Options-->Database Tools--> Data Connections-->SQL Server Instance Name, change it from sqlexpress to blank. After this, when you create a new connection, the server will be default to "." rather than ".\sqlexpress". So, you don't have to choose .\MSSQLSERVER which is invalid.

|||This is exactly the same problem I am having, Xinwei. -connecting to SQL 2005 from Visual C# Express, but I am in Visual C# Express and there is no Tools->Options->Database Tools. Can I change this manually somehow?

Thanks.|||I found this reference in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VCSExpress\8.0\DataSources\{067EA0D9-BA62-43f7-9106-34930C60C528}
Value=Microsoft SQL Server

...along side other data sources.

Are these not being loaded?

No comments:

Post a Comment