Click here to Skip to main content
15,911,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I am a MCA student and i have huge interest in .net technologies. To get more knowledge about these technologies i was doing some experimentation with VC#, SQL and ADO.net.

i am trying to access the database. i have two computers, i have connected these computers from LAN cable. i have installed the SQL server 2005 in my laptop and in other computer i have created a basic program.

now my objective is to get the data stored in the test table to my another computer.

i have tried below connection string but it wont worked:

SqlConnection con= new SqlConnection();
con.connectionstring="data source=Jhon-PC; initial catalog=jhon; uid=sa; pwd= test";
con.open();
String query="select * from test";


problem is same code works perfectly when database and program is on same computer, i am not able to understand the reason.

also like to inform you that i am trying to access the information in a grid view.

i want to understand that do i need to install some software on my laptop on which i have stored my database. or there is some other way to do this task..

Thanks for your help.
Posted
Updated 18-Dec-12 5:18am
v2
Comments
Member 9581488 18-Dec-12 11:14am    
Check your connection string here:
http://www.connectionstrings.com/
CHill60 18-Dec-12 11:37am    
Is Jhon-PC the name of the SQL Server instance on the other PC or is it a name you've given the PC? You should probably be using Server=Jhon-PC;Database=jhon; etc
Check that you can access the other PC from (e.g.) Explorer or browser.
Post the actual error message you get when you try to connect
jonlink01 18-Dec-12 12:41pm    
Hi Chill,

thank you for writing.

John-PC is a name of my laptop
john is a name of database
sa is a name of SQL server
test is a password
Member 9581488 18-Dec-12 16:05pm    
Try to connect using IP address of the comp that has Database.
Please go through the link once to check your connection string.
http://www.connectionstrings.com/
jonlink01 24-Dec-12 13:37pm    
Thank you for the above explanation. Just want to understand one more thing. i have free hosting space from SOMEE.com. Now i want to experiment little bit more. now what i want is i want to upload the same database on to the server. can you please help me in understanding the way to upload the database on the server and then extracting the information from the server to my computer. Thank you for your help. John.

1 solution

The data source in your connection string refers to the machine Sql Server is installed on. If you specify correct macine name, the client application tries to connect to the default instance of installed Sql Server (if there's a default instance)

Another type of instance is a named instance. The main difference is that a named intance cannot be connected to by using only computer name (or IP address alternatively). With named instance you have to specify bopth macine and the name of the instance of Sql Server.

Another thing is that when you connect to a Sql Server outside the local computer, you have to be able to communicate using proper ports. If there are firewalls in between the computers, a port to establish the connection must be opened. When using default setting with Sql Server the default port is 1433.

As already mentioned by another member, you can check the full syntax from http://www.connectionstrings.com/sql-server-2005[^]
 
Share this answer
 
Comments
jonlink01 24-Dec-12 6:21am    
Hi Mika,

Thank you for the above explanation.

Just want to understand one more thing. i have free hosting space from SOMEE.com. Now i want to experiment little bit more. now what i want is i want to upload the same database on to the server.

can you please help me in understanding the way to upload the database on the server and then extracting the information from the server to my computer.

Thank you for your help.

John.
Wendelius 4-Jan-13 15:15pm    
Unfortunately I haven't tried that service myself. But I would guess that uploading the data is similar to any other database instance once you get the connection working. Basically executing normal commands or using bulk insert if that's preferable.

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