how to connect web form with sql server running on an other computer in asp.net

纵饮孤独 提交于 2021-01-29 08:26:47

问题


i am creating an asp.net web application. i am using SQL server 2014 for database. i need configure a connection string on client computer web form project to access SQL server data on an other computer through query using asp.net c#. i disabled all firewalls on the host computer and also on client computer, enabled tcp/ip port setting, and enter the following connection string in client computer web configuration" this is the host server name"DESKTOP-H8JV03C" and prot is"1433"; but on ruining the query the browser give me the following error The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

<add name="nadra" 
     connectionString ="Data Source=DESKTOP-H8JV03C,1433;Initial Catalog=Nadra;Trusted_Connection=True;Integrated Security=True" 
       providerName="System.Data.SqlClient"/> 

回答1:


Integrated Security=True on your string means that its try to connect to the other server with the credential that asp.net pool have on the local computer.

If they are not match, probably not, then you need either make the same user on both computers with the same password that runs the pool, also have credential to runs on SQL Server , but better use a connection string that connects with the correct user id and pass of sql server on the remote computer.

something like:

<add name="nadra" 
     connectionString ="Data Source=DESKTOP-H8JV03C,1433;Initial Catalog=Nadra;Trusted_Connection=True;User ID=UserName;Password=Password" 
       providerName="System.Data.SqlClient"/> 


来源:https://stackoverflow.com/questions/53559624/how-to-connect-web-form-with-sql-server-running-on-an-other-computer-in-asp-net

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