问题
We are currently using the following connection string in our web.config file:
add name="DBConnectionString" connectionString="Data Source=ourServer;Initial Catalog=ourDB;Persist Security Info=True;User ID=theUserName;Password=thePassword" providerName="System.Data.SqlClient" />
This works fine. However, this app needs to be pushed to our external server. This means, according to our infrastructure team that we will need a connection string with ip address and port 1433 to be able to connect the app to our db which is not on the same external server.
I have tried any of the two connection strings below but they don't work.
The first one doesn't error out but just doesn't recognize the db. I suspect it is because of this bit
tcp:10.database.windows.net
Do I need to replace it with IP Address? I am told I need the tcp in there.
<add name="DBConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:10.database.windows.net,1433;Initial Catalog=POLLWORKER_TRAINING;Integrated Security=False;User Id=pworker;Password=pworker;Encrypt=True;MultipleActiveResultSets=True" />
This last one is causing an error which says,
the element connectionStrings cannot contain text. List of possible elements expected, "add", "remove", "clear"
<add name="DBConnectionString" connectionString="Provider=sqloledb;Data=10.22.5.20,1433;Network Library=DBMSSOCN;Initial Catalog=ourDB;User ID=theUserName;Password=thePassword" />
回答1:
This Data=10.22.5.20,1433
in your connection string should be:
Data Source=10.22.5.20,1433
For more details see: SQL Connection Strings
来源:https://stackoverflow.com/questions/18639760/how-do-i-put-connection-string-with-ip-address-inside-web-config-file