Sharon Watinsan
Sharon Watinsan

Reputation: 9840

Connect a C# MVC application to a remote SQL Server database

I have a SQL Server database located at http://192.168.10.3/MyDB. I have created a C# MVC application, and I need to know the steps to connect my application to the above database.

Is it only replacing the connection string in the web.config file ?

Data Source=?? ;Initial Catalog=??;Integrated Security=SSPI;
User ID=??;Password=pwd;

If so what am I to replace where I have placed the ?? sign ?

Upvotes: 4

Views: 10507

Answers (4)

Alireza Abdollahnejad
Alireza Abdollahnejad

Reputation: 1037

Below is connection string you need for:

Data Source="192.168.10.3" ;Initial Catalog=MyDb;Integrated Security=SSPI; User ID=sa (for example);Password=whatever you set before;

Upvotes: 0

wilsjd
wilsjd

Reputation: 2248

The other answers here are good. In addition, ConnectionStrings.com can be your friend, especially if you are going to connect to various types of databases in the future. Select the database that you need to connect to and then you'll see the different connection strings you can use for that database.

http://connectionstrings.com/sql-server-2012#sqlconnection

Upvotes: 3

Vikramsinh Shinde
Vikramsinh Shinde

Reputation: 2878

you can try this

  1. create a new text document on your desktop - conn.txt
  2. change file extension to udl (conn.udl)
  3. double click to open the file in the first tab select appropriate provider 4 . in the second tab enter server name (ip address,port), username, password (check Allow saving password) and database name.
  4. test connection
  5. if the test reports success close the window.
  6. open the file with notepad, copy everything but the provider name and paste it back to connectionString

Upvotes: 1

Malcolm O'Hare
Malcolm O'Hare

Reputation: 4999

  • DataSource = 192.168.10.3
  • Initial Catalog = MyDB
  • User ID = whatever sql login you are using to access your SQL Server
  • Password = password for the sql login above

Upvotes: 5

Related Questions