Home > Software engineering >  How to connect SQL Server on Cloud Virtual Machine to Web App in C#?
How to connect SQL Server on Cloud Virtual Machine to Web App in C#?

Time:12-21

I am having a problem on connecting my web application on the cloud server. My application works perfectly on the Test Server (On-Prem) using this connection string

<connectionStrings> <add name="CONNECTIONNAME" providerName="MSOLEDBSQL" connectionString="Data Source=IPADDRESS; Initial Catalog=DBNAME; UID=USERNAME; PWD=PASSWORD; Connection Timeout=100000; Trusted_Connection=True; MultipleActiveResultSets=True;" /> </connectionStrings>

But when I use this connection string and change the Data Source, Initial Catalog to the Cloud Server information, Remove the UID and PWD because it has no authorization, It returned Object Reference is not set meaning the connection I am linking is incorrect.

Am I doing something wrong or what? Can someone help me solve my problem.

I already tried setting the Data Source to localhost and there is no improvement. I put already the Trusted Connection because there is no USERNAME and PASSWORD on SQL Server, I am only using Windows Authentication.

CodePudding user response:

Can you try the below connection string,

<connectionStrings> 
 <add name="CONNECTIONNAME" 
   connectionString="data source=localhost;
   initial catalog=<DBNAME>;
   Integrated Security=SSPI;
   Connection Timeout=100000;
   Trusted_Connection=True;
   MultipleActiveResultSets=True;" 
   providerName="System.Data.SqlClient" /> 
</connectionStrings> 
  • Related