Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,

I've c# app ,and I want to connect to sql server on other computer. I used the string connection in the database and put it in my app, but it didn't work? Also there're connected through switch?
Posted
Comments
Malli_S 27-Sep-12 6:04am    
What error you are getting? What do you mean by 'didn't work' ? Add some more details/code snippets to your question.

Moreover, are you able to ping to the remote machine from your local machine? Is database configure to access the remote users?

Are you sure your connection string is correct? A switch won't hinder you in accessing the database, but a router, a firewall could.
- Check if the TCP/IP connections is enabled for the server instance
- Check the firewall setting throughout the hops between the client and the server
- Check the connection with an other tool
 
Share this answer
 
Comments
Member 8584763 27-Sep-12 6:09am    
the connection string is correct
-TCP/IP is enabled.
-firewall ,I did open a port for remote access.
-if I tried connect them directly will it make a different
Zoltán Zörgő 27-Sep-12 6:55am    
What is the exact error message you get?
Take a look with process explorer or other tool to see the tcp level connection status on both the server and the client side
Member 8584763 27-Sep-12 7:01am    
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)

System.Exception {System.Data.SqlClient.SqlException}
Zoltán Zörgő 27-Sep-12 7:13am    
This could be anything.
- Is the client and the server on the same LAN (physical, vlan, address space)
- can you ping the server from the client using the same name you added in the connection string
- can you ping it via it's ip?
- download portqry (http://www.microsoft.com/en-us/download/details.aspx?id=17148) and try to query the 1433 port
- read also this article about connectivity and firewall related settings: http://support.microsoft.com/kb/287932
- use a network sniffer like microsoft network monitor or whireshark to track network traffic between them

...but I have the feeling, you are treating some basic requirement as trivial but it is no. I suggest, you rethink and retest everything step by step
Member 8584763 27-Sep-12 7:50am    
I tried a switch and connect them directly .
How to ping the server
Connect SQL server from remote pc
1. share your database on LAN/WAN
2. set new connection string in exe/text file [where sql connection string is written]
 
step 1: follow steps given in this link [For access sql database remotely(from different pcs)]
http://support.microsoft.com/kb/914277[^]
 
step 2: after step 1 complete then change connection string's parameters, 
datasource = server-name OR IP-Address [which is in sharing now after step 1] ;
Initial catalog = your database name ;
UserId = sql server - user login Id ;
Password = sql server - user login password;



If error comes (err No: 18456) - can not connect from remote pc User not found in Domain
Reason : UserLock out (state-1)
sql server does not contain loginName like this...
this username(e.g. sa) is not created inside this server-name
Solution : create New Login in sql server-(With SQL authentication Mode)


Create New SQL Server Authenticate user login
sql -> object explorer ->security -> logins-> new login->

in new window
general tab-> Login name : abcd
                        check 'Sql server authentication'
                        Pwd =*** , confirm pwd=***
                        check 'Enforce pwd policy'
                        DO NOT check 'Enforce pwd expiration' (if check it will cause err: 18515)
Ok.
.
.
.
now, try to login
.
If err comes (err No: 18452)

solution : For sql 2000
                         start -> Program ->  sql server  -> enterprise Manager ->
                         server name -> properties ->security under authentication,
                         check 'Sql server & Windows'
           For sql 2005
                        sql -> servernm -> properties -> security ->
                        check 'Sql server & window Authentication mode'
Note: stop sql server & Agent services then start both services again.
     
Now disconnect sql server & connect again you will also able to Login through sql-authentication


Happy Coding!
:)
 
Share this answer
 
v3
Comments
Member 8584763 27-Sep-12 7:42am    
I did almost exactly like it said in step one except

In the TCP/IP Properties dialog box, on the IP Addresses tab, several IP addresses appear in the format IP1, IP2, up to IPAll. One of these is for the IP address of the loopback adapter, 127.0.0.1. Additional IP addresses appear for each IP Address on the computer. Right-click each address, and then click Properties to identify the IP address that you want to configure.

This time I connect them directly , I still get the same message
Aarti Meswania 27-Sep-12 7:54am    
try to login on server using other pc which have sql
find ip address of server pc using command-prompt ipConfig command and use that
1. server
2. client
from client pc's sql-server try to login on server pc's sql
it will be easy to test
and also make sure that Firewall settings are configured properly (you have added exes in Exception-tab) and sql-agent service is running on server-pc
Member 8584763 27-Sep-12 7:58am    
last step isn't clear
it will be easy to test
and also make sure that Firewall settings are configured properly (you have added exes in Exception-tab) and sql-agent service is running on server-pc
Aarti Meswania 27-Sep-12 8:00am    
have you done firewall settings on server?
Member 8584763 27-Sep-12 8:01am    
yes

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900