Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sqlexpess

Author  Topic 

venkatvamsi2003
Starting Member

4 Posts

Posted - 2008-10-09 : 01:48:24
i've installed sqlexpress and sql server management studio 2005.My server name is patrick\sqlexpress.now when i'm trying to connect to the sql database from asp.netwith connection string i used as
user id=patrick\sqlexpress .But i'm getting an error that the connection string shouldn't contain "\" .How can i connect to the database.plz help me out

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 02:02:41
refer this for the values to be set

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx
Go to Top of Page

venkatvamsi2003
Starting Member

4 Posts

Posted - 2008-10-09 : 02:21:01
this is the error i get when i try to connect to a database


An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 02:23:39
quote:
Originally posted by venkatvamsi2003

this is the error i get when i try to connect to a database


An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


have you enabled remote connections option from sql surface configuration manager?
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-09 : 03:12:54
Sounds to me that you are using c# ???

For connections strings you can use Visakh's example above or try www.connectionstrings.com.

Also sounds like you are declaring your connection string on the fly if thats the case you should either use two slashes ie

myconnection.ConnectionString = "Data Source=patrick\\sqlexpress ......etc"



And if you dont want to use the above approach, then you have to put and @ sign before your variable

myconnection.ConnectionString = @"Data Source=patrick\sqlexpress ......etc"
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-09 : 03:25:38
Oh, by the way..., if its a connection string problem.

For best practice put it in the web.config file and declare it in your classs and call it in your code behind, thereby having an n-tier application

web.config

<connectionStrings>
<add name="myConnectionString" connectionString="Server=00.000.000.00,1433;Database=mydb;Uid=username;Pwd=password;"
providerName="System.Data.SqlClient" />

</connectionStrings>






your class



SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString.ToString());
Go to Top of Page
   

- Advertisement -