Search code examples
asp.netsql-serverweb-config

How to connect ASP.NET app to remote SQL Server


I need help connecting my Web App to a remote database (SQL Server). I have tried many suggested solutions but I can't seem to come right.

This is how I connect to a local database, it works 100%:

<add name="DBCS" connectionString="Data Source=serverName;Initial Catalog=MVNE_Website;Integrated Security=True" providerName="System.Data.SqlClient" />

My ASP.NET Web App is hosted on one server, and the database is on a separate server.

The remote DB server is 100% configured to allow remote connections and firewall rules also adhere to the connection protocols. I think it is just my connection string that is incorrect but I don't know why??

Here it is(conn string for remote SQL server)

<add name="DBCS" connectionString="server=serverIP\serverName; database=MVNE_Website; Integrated Security=True" providerName="System.Data.SqlClient" />

I don't use a username or password when connecting to this remote SQL Server so I did not see a point in adding it in the conn string?


Solution

  • :/

    In my web.config file custom errors mode was on RemoteOnly, so I turned it off and saw that my connection string was never the problem, the actual problem was that the app was trying to insert null into a primary key field that does not allow null, i never set the PK to auto increment .. sorry and thanks