views:

52

answers:

3

Hi,

I have MSSQLServer 2005 installed on my machine. I am creating a connection string like this:

String sqlConnectionString= user id=admin; password=admin; server=MachineName\MSSQLSERVER; Trusted_Connection=no; database=MYDataBase; connection timeout=30

When I do: myConnection = new SqlConnection(sqlConnectionString);
myConnection.Open();

Open() command throws an exception :

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25

Also the same string works fine on SQLEXPRESS/

**I have configured Sql Express to accept remote connections by choosing "Local and remote connection".Also I started SQL Browswer service.**

Is there anything wrong in connection string?

A: 

Have a look at http://www.connectionstrings.com/sql-server-2005

And verify that your names are correct.

Mo
+1  A: 

You must have made a typo somewhere. Try this:

  1. Load up Visual Studio.
  2. Go to the "Server Explorer" tool window.
  3. Create a new data connection.
  4. Fill in your required values, click the "Test Connection" button to make sure they work, then click OK.
  5. Click on your new connection in the "Server Explorer", and you can copy and paste the connection string from the Properties tool window.
Christian Hayter
Thanks Christian
Ashish Ashu
A: 

Make sure that you have ‘SQL server and Windows Authentication mode’ set under ‘Server authentication’ in ‘Security’ properties. Your connection string implies that you are using SQL authentication. If you have ‘Windows Authentication mode’ set you may receive this error.

Try setting the server name to just the name of your machine, as in ‘server=MachineName;’.

Curt