Click here to Skip to main content
14,456,102 members
Rate this:
Please Sign up or sign in to vote.
See more:
SqlConnection con = new SqlConnection(@"Data Source=myconnect\MSSQLSERVER;Initial Catalog=IPC2;Persist Security Info=True;User ID=sa;Password=----");


An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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 - Connection string is not valid)


i need help for this thanks

What I have tried:

i want to try diffrent connection so i need some help thanks
Posted
Updated 24-Jul-19 20:04pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The error message is pretty explicit: the SQL server instance you are trying to connect to isn't there.
Start here: Simple SQL Connection String Creation[^] and use Windows to establish a working connection string, then use that in your app.

But ... a couple of things on connection strings.
1) Don't hard code them. Connection strings are one the the things that should definitely change between dev and production - you should never test against production databases because ... well, isn't it rather obvious? So hard coding means you have to change every single time it's used when you release your software, and that means you are releasing untested software! Store them in a config file so that the string is not part of your app, and can be changed without altering your EXE. Have a look here: Instance Storage - A Simple Way to Share Configuration Data among Applications[^] - it may help.
2) Never use the sa account for general users: it's very dangerous. If your code is slightly wrong, or worse prone to SQL Injection, it gioves far, far too much power to the user. Connections should be made using a user with the minimum permissions they need to do their job - which does not include creating and deleteing databases!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100