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

∥☆過路亽.° 提交于 2020-01-14 10:33:10

问题


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 ?


回答1:


  • 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



回答2:


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




回答3:


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



回答4:


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;



来源:https://stackoverflow.com/questions/15772779/connect-a-c-sharp-mvc-application-to-a-remote-sql-server-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!