Click here to Skip to main content
12,948,021 members (89,011 online)
Rate this:
Please Sign up or sign in to vote.
See more:
good afternoon,

i am trying to connecting to sql server which is present in visual studio 2010.

I am giving the connection string as

SqlConnection con = new SqlConnection("Data Source='RajasekharServer';Initial Catalog=RajasekharDatabase;User Id=scott;Password=tiger;");

it is showing the error message as

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

it is not connecting to sql server which is present in visual studio.

please help me.
Posted 16-Feb-13 20:28pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Check your connection string there will some issue and put connection string in Web.Config

<add name="DatabaseLog" connectionString="Data Source=DataSource;Initial Catalog=XYZ;Persist Security Info=True;User ID=ABC;Password=ABC" /> <connectionstrings>
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Try to get the appropriate connection using visual studio 2010 database connection wizard.

In the menu, go to Tools
-> Connect to database
-> A popup will appear
--> type the server name
--> use sql authenticaltion mode if configured
--> a list of database will appear, select your desired database.

Now, go to Server Explorer, your database will appear in the list, right click on it, a property window will appear under that you can see connection string

Just copy that string and paste in web.config file

Hope this will help

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,628
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web01 | 2.8.170518.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100