You are on page 1of 5

6/12/2016 NotabletoconnectDatabasefromweb.configinasp.

netCodeProject

12,325,395 members 67,433 online Sign in

articles quick answers discussions community help Searchforarticles,questions,tips


Ask a Question All Unanswered FAQ

Not able to connect Database from web.config in


asp.net
See more: ASP.NET SQLServer Rate this:

Hi All,

i am not able to connect to database using connection string in web.config please help me , i am
getting this type of error page, please help me how to write connection string in web.config using
userid and password of my sql server

A networkrelated or instancespecific error occurred while establishing a connection to SQL Server. The Top Experts
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: Named Pipes Provider, error: 40 Could not open Last 24hrs This month
a connection to SQL Server
OriginalGriff 194 OriginalGriff 4,060

CHill60 171 Sergey Alexandrovi 2,934


Description: An unhandled exception occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where it originated in the code. BillWoodruff 170 CPallini 1,485

Sergey Alexandrovi 163 ppolymorphe 1,460


Exception Details: System.Data.SqlClient.SqlException: A networkrelated or instancespecific error
occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Karthik Bangalore 145 Dave Kreskowiak 1,376
Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
provider: Named Pipes Provider, error: 40 Could not open a connection to SQL Server

Also Read
Thanks
<big>sudheer.N</big>
Free OCR SDKs vs Paid OCR
SDKs

Posted 21Dec11 22:37pm


sudheer.learner 488

Real World OCR

Add a Solution

Comments

sriman.ch 22Dec11 4:43am


It amy be due to incorrect credentialsusername and password and incorrect datasource...check your
connectionstring once or else provide your connectionstring....

sudheer.learner 22Dec11 5:03am

sudheer.learner 22Dec11 5:05am


My Connection String is like that

6 solutions Top Rated Most Recent

Solution 1 Rate this:

From link[^]:
Basically, when you failed to connect to your SQL Server, the issue could be:
1 Network issue,
2 SQL Server configuration issue.
http://www.codeproject.com/Questions/304127/NotabletoconnectDatabasefromwebconfiginas 1/5
6/12/2016 NotabletoconnectDatabasefromweb.configinasp.netCodeProject

3 Firewall issue,
4 Client driver issue,
5 Application configuration issue.
6 Authentication and logon issue.

Check these
Steps to troubleshoot SQL connectivity issues[^]
SQL Server 2005 Connectivity Issue Troubleshoot Part I[^]
Troubleshoot Connectivity Issue in SQL Server 2005 Part II[^]
Troubleshoot Connectivity Issue in SQL Server 2005 Part III[^]

BTW check this bunch also for future errors

Posted 21Dec11 23:05pm


thatraja 248K

Comments

amitgajjar 22Dec11 7:44am


5 for you :

Solution 2 Rate this:

Hi Sudheer,

hope this will help u

Hide Copy Code


<connectionStrings>
<addname="Default"connectionString="DataSource=UrserverIP;User
Id=sa;password=sa;InitialCatalog=URDBName/></connectionStrings>

Regards,
Sucharitha

Posted 21Dec11 23:12pm v2


RagSuchi 683

Comments

sudheer.learner 22Dec11 5:35am


Hi Sucharitha,

thanks for your solution , but now also i am not able to connect it shows some error
could you please send me connection string and how to access that in c#.net
i use in web.config

and access this in c#.net is


SqlConnection con = new
SqlConnectionSystem.Configuration.ConfigurationManager.ConnectionStrings["TFAConnection"].ConnectionString;

it show error like error: 40 Could not open a connection to SQL Server
please help me sucharitha

sudheer.learner 22Dec11 5:36am

Solution 3 Rate this:

Hi Sudheer,

Some check list

http://www.codeproject.com/Questions/304127/NotabletoconnectDatabasefromwebconfiginas 2/5
6/12/2016 NotabletoconnectDatabasefromweb.configinasp.netCodeProject

1. Check that your SQL server is exposed to tcp/ip protocol using SQL Server Configuration Manager.
2. Check the format of your connection string

Hide Copy Code


<addconnectionstring="Server=<ServerName>;UserID=<UserName>;Password=
<Password>;Database=<DatabaseName>"name="<ConnectionStringName>"/>

3. Check that your SQL Server is using mixed mode for the authentication.

Thanks
Vinod

Posted 21Dec11 23:39pm


Vinod Satapara 10.4K

Comments

sudheer.learner 22Dec11 6:01am


Now also i am not able to connect Vinod , could you please connect to my System
throw teamviewer

Solution 4 Rate this:

<AppSetting>
<add key="SqlConnectionString" value="Data
Source=ServerName;DataBase=DatabaseNAme;UID=sa;PWD=pass;Min Pool Size=10; Max Pool
Size=100"/>
</AppSetting>
check your name which you are enter.

Posted 22Dec11 17:19pm


chetan virkar 3K

Solution 5 Rate this:

Hide Copy Code


<AppSetting>
<addkey=conn;value="DataSource=ServerName;DataBase=DatabaseName;User
ID=sa;Password=pass"
oto>solutionexplorer>

Posted 22Dec11 18:04pm


Vasim889 2.3K

Solution 6 Rate this:

Try this

Solution 1 :

If your SQL server is SQL Server Authentication then just use following Connectionstring

<AppSetting>
<add key=Connectionstring; value="Data
Source=ServerName;DataBase=DatabaseName;UserId=sa;Password=sa">
</AppSetting>

And access this Connectionstring as

using System.Configuration;
string str = ConfigurationManager.AppSettings["Connectionstring"];

http://www.codeproject.com/Questions/304127/NotabletoconnectDatabasefromwebconfiginas 3/5
6/12/2016 NotabletoconnectDatabasefromweb.configinasp.netCodeProject

Solution 2 :

If your SQL server is Windows Authentication then just use following Connectionstring

<AppSetting>
<add key=Connectionstring; value="Data Source=ServerName;DataBase=DatabaseName;Integrated
Security=false">
</AppSetting>

using System.Configuration;
string str = ConfigurationManager.AppSettings["Connectionstring"];

I think this will solve the problem...

Posted 22Dec11 20:08pm


Sachin Suryawanshi 533

Add your solution here

B I U S small BIG code var < > & link [^] encode untab case indent outdent

Preview

Existing Members ...or Join us


Sign in to your account Download, Vote, Comment, Publish.

Your Email Your Email

Password Optional Password

Forgot your password?


I have read and agree to the Terms of Service
and Privacy Policy
Please subscribe me to the CodeProject
newsletters

Submit your solution!

When answering a question please:

1. Read the question carefully.

2. Understand that English isn't everyone's first language so be lenient of bad spelling and
grammar.

3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question
and fix the problem. Insults are not welcome.

Let's work to help developers, not make them feel stupid.

http://www.codeproject.com/Questions/304127/NotabletoconnectDatabasefromwebconfiginas 4/5
6/12/2016 NotabletoconnectDatabasefromweb.configinasp.netCodeProject

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

Advertise | Privacy | Mobile Layout: fixed | fluid Copyright CodeProject, 19992016


Web02 | 2.8.160531.1 | Last Updated 23 Dec 2011 All Rights Reserved. Terms of Service

CodeProject, 503250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 4168498900 x 100

http://www.codeproject.com/Questions/304127/NotabletoconnectDatabasefromwebconfiginas 5/5

You might also like