
Connection string Error


Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Hi, If your database is MSSQL then you can troubleshoot by checking the following:
1. make sure your SQL Server instance/ SQL Server Services is running.
2. make sure TCP/IP is enabled. This you can do from SQL Server Manager. Also, check Default port:1433
3. Make sure the firewall is not blocking the SQL Server.
4. Enable Remote Connection in SQL Server Properties.
Details are available below the article.
https://www.c-sharpcorner.com/article/resolve-error-40-could-not-open-a-connection-to-sql-server/

It seems your data source is not correct, check your data source name or If database is on your local machine try the following:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=.;Initial Catalog=testDB;User id=root;Password=mysql";
if (conn.State != ConnectionState.Open)
conn.Open();
Gajendra JangidPosted Mar 22, 2022, 2:40 AM