SQL connection string for database on network

10,328

Solution 1

If the mdf file is not attached to an instance of sql server and you want to connect to the database while it does not exist on the same machine as your application, you need first to copy the database to the server with the mentioned IP and attach it to an instance of sql server installed on that server. The connection string in this case -if you have a domain and will be authenticated to the database server by windows authentication- will be as follows:

"data source=10.15.10.12; integrated security=SSPI;initial catalog=database1"

Or you can create a sql server user on the database sever and connect using the following connection string:

"data source=10.15.10.12; initial catalog=database1;user id=<username>;password=<password>"

Solution 2

http://www.connectionstrings.com/sql-server-2008

Solution 3

create a file on your desktop called test.udl open it up and follow the steps to connect to your database then click test to make sure it works. then open the file in notepad, it will be 1 line and contain the connection string

Share:
10,328
Saeed
Author by

Saeed

I am an IT engineer and work in electronic found transfer area.

Updated on June 04, 2022

Comments

  • Saeed
    Saeed almost 2 years

    I want to connect to a database on a host except localhost, my DBMS is SQL Server and I'm using ado.net, like this:

    SqlConnection con = new SqlConnection(constr);
    con.Open();
    SqlCommand cmd = new SqlCommand("insert into st (ID,Name) values ('"+cnt.ToString()+"','havijuri');", con);
    //some sql commands.
    con.Close();
    

    what should I use as the constr (connection string), and with these information:

    • host IP: 10.15.10.12
    • the file is database1.mdf,
    • in this directory(on the host): D:\Project1\DataBase

    Tell me if any other information is needed

  • TomTom
    TomTom almost 14 years
    It explains all connection string possibilities. Reading it is enlighting.