问题
At the moment I have the following <connectionStrings> definition in my
Web.config` file:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>
I didn't write this though, so I have a feeling that it was automatically created by Visual Studio.
My database is hosted on a separate server on our network, so how do I define it and the database username and password?
For the sake of the example, the server information and credentials are:
Server address: sql-database / 10.0.0.11
Username: myUsername
Password: myPassword
回答1:
Server Name: IP-Address\Database-instance,Port
You can not directly. you need to have TCP/IP
enabled and configured the TCP/IP Ports
on sql server configuration manager at remote server.
Go through it: Configurations-Remote-Server
Or if it already configured then just contact DBA
for the hosted server for providing the proper connection string.
you need to have TCP/IP connectivity .Just launch it, enter the DNS host name or IP address in the Server Name'
box and hit Connect. The hosting company needs to have enabling TCP/IP on your SQL Server instance, and them providing you with secure access to the IP address that instance is running on.
Then it would be in this form:
connectionString="Data Source=Server_Name;Initial Catalog=Database_Name;
User ID=XXXX;Password=XXXX;Integrated Security=True;"
providerName="Provider_Name"
Most administrators do not allow direct access to the SQL Server from outside the firewall. In that case, if you can connect to the host over VPN then you should be able to connect directly to the server with Enterprise Manager or SQL Management Studio.
回答2:
Modify your connection string as
connectionString = "data source=sql-database / 10.0.0.11; User ID = myUsername; PassWord = your password "
回答3:
Try using Connection String in this Format
<connectionStrings>
<add name="SQLconnString" connectionString="Data Source=246.185.231.253;Initial Catalog=DNAME;User ID=SampleUID;Password=SamplePWD;timeout=6000" />
</connectionStrings>
This Might help you!
来源:https://stackoverflow.com/questions/12121542/defining-connectionstring-for-remotely-hosted-sql-server