Sunday, March 25, 2012

Connecting to SQL Express Database in C# Application

I'm trying to connect to a sql express database on my local machine, using the following connection string:

SqlConnection thisConnection = new SqlConnection(@."Data Source=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf");

However, I keep getting an error message saying "An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections."

Why would my application be trying to connect remotely when the database is on my local machine? And how can I fix this problem?

Thanks

There 'should' be three major components to a connection string: source (or server), catalog (or database), and security information. You have only a source listed.

Check out legitimate SQL Server connection strings at: http://connectionstrings.com/?carrier=sqlserver2005

|||Thanks for the help!

No comments:

Post a Comment