问题
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
- create a new text document on your desktop - conn.txt
- change file extension to udl (conn.udl)
- 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.
- test connection
- if the test reports success close the window.
- 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