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
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 connection string

Author  Topic 

Exir
Posting Yak Master

151 Posts

Posted - 2013-04-28 : 15:38:42
Hi
I have written a windowsbase program, this program should be used by some users in different computers in local net.
i Have some problem with its connection string.
I wrote this connection string first :
app.config :
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|datadirector y|\db\project1db.mdf;Initial Catalog=project1db;Integrated Security=True"

command :
SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=project1db;Integrated Security=True");

It works properly in my computer but when i make a setup of my program and install it on another computer, an error says :

can not open database "projectdb" requested by the login . The login failed.
Login failed for user "ZYZY-PC\ZYZY

1- Is my connection string correct ? and it should work properly in all computers , isnt it? why it doesnt work ?

2- i want to have a database that all computers use it, Is it true to replace my computer IP instead of . (dot) in connection string ? if so why it is not working even on my own computer

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-28 : 18:21:36
The dot in ".\SQLEXPRESS" stands for the local machine. (You could also use (local) including the brackets instead of the dot).

When you try to connect from a remote machine, obviously you cannot use the dot or (local) which are symbolic names for the local machine. Instead you should use the IP address or CNAME or network name for the computer. So your connection string should be YourCompterName\SQLExpress. You can learn a great deal about connection strings for various situations from connectionstrings.com

If that does not work, then you have to do more work to figure out why it is not connecting. Couple of simple things you should do are a) see if you can ping the server box from your remote machine. b) Make sure that remote connections are enabled on the server box. (see here for step by step instructions: http://msdn.microsoft.com/en-us/library/ms191464.aspx )

If that does not help, you will need to do still more work. See this page:http://blogs.msdn.com/b/sql_protocols/archive/2006/09/30/sql-server-2005-remote-connectivity-issue-troubleshooting.aspx
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2013-05-07 : 10:22:43
I used name of my computer as you said, but it still not working on other computers in network
my connection string :
SqlConnection cn = new SqlConnection(@"Data Source=ZY-PC\SQLEXPRESS;Initial Catalog=project1db;Integrated Security=True;");

Error :
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

please help , i really dont know what to do
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-07 : 10:31:23
Try the other things that I listed in my previous post >>>>



Couple of simple things you should do are a) see if you can ping the server box from your remote machine. b) Make sure that remote connections are enabled on the server box. (see here for step by step instructions: http://msdn.microsoft.com/en-us/library/ms191464.aspx )

If that does not help, you will need to do still more work. See this page:http://blogs.msdn.com/b/sql_protocols/archive/2006/09/30/sql-server-2005-remote-connectivity-issue-troubleshooting.aspx
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2013-05-10 : 11:58:41
Thank you James , Your links were really useful, specially this one : http://blogs.msdn.com/b/sql_protocols/archive/2006/09/30/sql-server-2005-remote-connectivity-issue-troubleshooting.aspx

Now it can connect to the server but this error message appears: login failed for user ZY-PC\Guest
While i dont use windows authentication and i defined user/pass for sql and set it on Mixed mode !
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-10 : 13:17:16
I am not 100% clear on the scenario that you have, so what I am suggesting below are a series of steps to identify where the problem is.

1. Can you connect and login to a database on ZY-PC from SSMS on the same computer sql auth? (I assume the answer is yes).

2. Can you connect and login to a database on ZY-PC from SSMS on the same computer Windows auth?

3. Can you connect and login to a database on ZY-PC from SSMS running on another computer using sql authentication?

4. Can you connect and login to a database on ZY-PC from SSMS running on another computer using Windows authentication?

5. Can you connect and login to a database on ZY-PC from your application running on ZY-PC using sql auth?

6. Can you connect and login to a database on ZY-PC from your application running on ZY-PC using windows auth?

7. Can you connect and login to a database on ZY-PC from your application running on another computer using sql auth?

8. Can you connect and login to a database on ZY-PC from your application running on another computer using windows auth?

Testing those scenarios would/should give some insight into where we need to look to figure out what the problem is.
Go to Top of Page

Exir
Posting Yak Master

151 Posts

Posted - 2013-05-11 : 12:27:25
Thank you verrry much James for answering.
The problem above is solved and i could successfully remote on sql in other laptop
but it was just a test at home to learn it and perform at office,
I happily went to office and perform all steps in the links above you gave, but unfortunately it didnt work !
the error was :

Named Pipes Provider, error: 40 – could not open a connection to SQL server

I enabled TCP/IP and Named Pipe and also set port 1433 for them
and "Allow remote" is checked in sql
and I closed the firewall inorder not to close the sql port, but it didnt work

Did I miss any step ?
I could not find any further information in the net :(
Please help me
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-05-11 : 16:10:17
Doing the eight scenarios I listed in an earlier post might help you narrow down the problem.

Also, is the instance a named instance? If so you need to specify the instance name in the connection string.
Go to Top of Page
   

- Advertisement -