Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

When I am trying to connect to SQL Server using the below code:

SqlConnection con = new SqlConnection("Server=localhost,Authentication=Windows Authentication, Database=employeedetails");

con.Open();

SqlCommand cmd;

string s = "delete employee where empid=103";

I am get the below error: 

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)

1 Answer

0 votes
by (12.7k points)
edited by

A connection string for the SQL Server should be looking more like: "Server= localhost; Database= employeedetails; Integrated Security=True;"

If you are having a named instance of the SQL Server, you would be needing to add that as well, e.g., "Server=localhost\sqlexpress"

If you want to learn more about SQL, Check out this SQL Certification by Intellipaat. 

For more information visit :

Related questions

0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Browse Categories

...