简体   繁体   中英

Problem in the connection string of Microsoft SQL Server 2005 !

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?

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.

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

And verify that your names are correct.

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;'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM