
Connection string Error

3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 19, 2022, 2:56 AM EDT
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();
Satya KarkiRank #78 · 24.6K reputationPosted Mar 20, 2022, 12:53 PM EDT
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/
Gajendra JangidRank #157 · 14.9K reputationPosted Mar 21, 2022, 10:40 PM EDT