Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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
good
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" />
  Permalink  
Rate this: bad
good
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
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
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