Reputation: 31
I am going through a windows application in C#.net using SQL Server 2008 as database server. The following is the code in my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myconnection" value="Data Source=ritesh-pc\SQLEXPRESS;Initial Catalog=dbname;Integrated Security=SSPI"/>
</appSettings>
</configuration>
Whenever I try to access that key
"myconnection" as string connectionString = ConfigurationSettings.AppSettings["myconnection"];
the following error occurs
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: 26 - Error Locating Server/Instance Specified)
Upvotes: 3
Views: 176
Reputation: 9081
The problem is in the connection string , I think you must set your account parameters (if you have) like this
Data Source=.\SQLEXPRESS;Initial Catalog=attendence;Integrated Security=SSPI;
User ID=myUsername;Password=myPassword;
For full details : check this
Upvotes: 0
Reputation: 6876
You want something like
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
Please refer to Store connection string in web.config I find the article very useful
Upvotes: 1
Reputation: 458
Upvotes: 1
Reputation: 937
I got the same error before and what I do is :
How to resolve Error 26 in SQL Server?
I tried using the (IP address of the server)\SQLEXPRESS. Sometimes instance name is unrecognizable better use the IP address of your sql server.
or maybe you've got a wrong connection string. In your app.config check if the syntax is like this:
<add name="conString"
connectionString="Data Source=10.99.89.80;Initial Catalog=EWB_FileDownloader;User ID = sa; Password = 12435@"
providerName="System.Data.SqlClient" />
Upvotes: 0
Reputation:
This could be that your connection string is wrong/inaccessible due to passwords/etc.
Upvotes: 1