Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remote sql connection

Status
Not open for further replies.

bbartlin

Programmer
Jan 8, 2004
35
US
I have a connection string in an app that will be installed on a server that doesn't have sql server. It needs to connect to another machine in the domain. Is there a way to do this? Is there a remote server paramater or something to use with the ConnectionString?

Any help will be appreciated...

Here is my simple connection string, but doesn't go to a remote machine. It doesn't even pay attention to the Server parameter.

//Make data connection
SqlConnection dataConnection1 = new SqlConnection();
dataConnection1.ConnectionString = "Integrated Security = SSPI;" +
"Server = " + txtServer + ";" +
"Initial Catalog = " + txtCompanyName.Text + ";" +
"Data Source = (local)";

dataConnection1.Open();
 
You have to add user id and password :
Code:
string connectionstring="user id=george;Password=admin1;Initial Catalog=mySQLDataBase;Data Source=ServerDC790;Connect Timeout=30"
Where
ServerDC790 is the machine where SQL is running
If SQL is running on the same machine as the app then replace ServerDC790 with localhost.
Code:
string connectionstring="user id=joe;Password=admin;Initial Catalog=mySQLDataBase;Data Source=localhost;Connect Timeout=30"
-obislavu-


 
bbartlin,
All you have to do is specify the name of the computer where SQL server is in the Data Source attribute. Like this:
Code:
dataConnection1.ConnectionString = 
 "Integrated Security = SSPI;" + 
 "Server = " + txtServer + ";" + 
 "Initial Catalog = " + txtCName.Text + ";" +
 [b]"Data Source = RemoteMahinceName"[/b];
Hope this helps!

JC


_________________________________________________
To get the best response to a question, read faq222-2244.
 
Turns out that it was working, but I had both Server and Data Source. They mean the same thing...

I was setting Server to the correct machine, but then setting Data Source to local made it point back to the machine that it was installed on.

Thank you both for your replies, they were both valuable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top