4
Answers

sqlConnection problem

waffle

waffle

18y
4.6k
1
visual studio 2005 here's my connection.. SqlConnection connect = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" + "Initial Catalog=dbname";); i don't if this is the problem or what. i just created a database inside this visual studio which is the ms sql server. the error says... an error has occurred while establishing a connection to the server. when connecting to Sql Server 2005, the 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) i even tried allowing local and remote connection in the settings but still it doesn't work. and i think, i don't need to do that because I'm not connecting remotely. i don't know that's how i understand it.. pls help me! tnx
Answers (4)
0
bhargav

bhargav

NA 8 0 17y
This is the solution for ur problem

InitialCatalog=Testdb;DataSource=.\\sqlexpress;Pooling=True;User ID=sa;Password=sa

0
waffle

waffle

NA 48 0 18y
now im using this connection string... Data Source=.\\sqlexpress;Initial Catalog=mydb;Integrated Security=true the problem now is that it cannot open the database requested by the login. it's saying that login failed. it appears on my conn.Open();
0
Gurdeep

Gurdeep

NA 26 0 18y
Jut do the following on the load form event

Dim conTransit As SqlConnection
conTransit = New SqlConnection("Server=SERVER;Database=DATABSE;Integrated Security=SSPI")

'YOU COULD USE --- [User ID=USER;Password=PASSWORD] INSTEAD OF [Integrated Security=SSPI]if your sqlserver does
'not have windows default access

Try
'Try the SQL-SERVER connection
conTransit.Open()
'Additonal check statements
If conTransit.State = ConnectionState.Open Then
MessageBox.Show("Connection OK" & "" & conTransit.ConnectionString)
Else
MessageBox.Show("Could not open SQL database Connection : " & "" & conTransit.ConnectionString)
End If

' -----------------------Genrate error meaasge-------------------------------------

Catch er As System.Data.SqlClient.SqlException
MsgBox("You have Problem generating SQL Server Connection" & "--->" & er.Message, MsgBoxStyle.Critical, "MY SYSTEM ERROR!")
End Try

Enjoy................
0
Keith Roesch

Keith Roesch

NA 8 0 18y

Hello,

Do as follows
  
Under sql server 2005 go into configuration and select SQL Server surface and configuration.
Click the link for Surface Area Configuration for Services and Connections  
next for standard SQL conections expand Database Engine, then click Remote Connections.
There you will select local and remote connections and also select Using both TCP/IB and named pipes.

If you use SQLExpress expand and use the above sitings here also.

any questions
http://www.terranettech.net