How do I put connection string with IP Address inside web.config file?

假装没事ソ 提交于 2020-01-03 05:21:57

问题


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

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