ConnectionString problem.Can not communicate with database after iis deployment - c#

After publishing my locat asp.net website to IIS server, it can not communicate with database. I'm checking if the api are working properly with Postman. And here is the error.
<connectionStrings>
<add name="HsptlMgmnt" connectionString="server=amso1; database=hoptialfinaldb;Trusted_Connection=false;uid=tanvir;password=1234;" providerName="System.Data.SqlClient" />
</connectionStrings>

Related

Connect to SQL Server in web.config (ASP.NET MVC) using Windows authentication not working, why?

It is under configsection but it's not working and it didn't connect to SQL Server. Can anyone help me with this problem?
Of course, my data source name is . not other thing.
<connectionStrings>
<add name="CompanyContext"
connectionString="Data Source=.;Integrated Security=SSPI;Initial Catalog=Learning_EFCF;"
providerName="System.Data.SqlClient" />
</connectionStrings>

Hosting WCF service in Windows service

There is a client in the form of an ASP.NET MVC application, there is a WCF service, requests to the WCF service are sent from the client, the service itself manipulates database data through the Entity Framework. Everything works locally in the Visual Studio development environment via IIS Express, but when I deploy this service on a Windows service, an error appears
"The underlying provider failed on Open."
DB connection string in app.config
<connectionStrings>
<add name="AddressBookEntities"
connectionString="metadata=res://*/ContactModel.csdl|res://*/ContactModel.ssdl|res://*/ContactModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\AddressBook.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
I suggest you use SQL Server Express, attached filename requires a particular user context

ASP .NET web api application database error after deployed to Azure

I have an ASP .NET web api project that connects to MS SQL database using entity framework. The project works fine when ran locally.
I published the project on Azure, created a DB in cloud, also added the necessary tables in the DB. After the website is published, everything seems to be fine until I try to access the controller (Eg: mywebsite.azurewebsites.net/api/Groups), I get this error:
I have Enable Migration before publishing my project. When enabling migration, I got an error saying there are two DB: ApplicationDbContext, and myDB (which is where the tables are). So I enabled migration only on myDB. Does the error has anything to do with that?
EDIT:
Here is the connection string from Azure and web.config file:
Web.Config file:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=tcp:xxxxxxxxx.database.windows.net,1433;Initial Catalog=IMS;User Id=userName#xxxxxxxxx;Password=myPassword" providerName="System.Data.SqlClient" />
<add name="IMSEntities" connectionString="metadata=res://*/Models.IMSEntities.csdl|res://*/Models.IMSEntities.ssdl|res://*/Models.IMSEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:xxxxxxxxx.database.windows.net,1433;Initial Catalog=IMS;User Id=userName#xxxxxxxxx;Password=myPassword"" providerName="System.Data.EntityClient" />
<add name="IMSEntities_DatabasePublish" connectionString="Data Source=tcp:xxxxxxxxx.database.windows.net,1433;Initial Catalog=IMS;User ID=userName#xxxxxxxxx;Password=myPassword" providerName="System.Data.SqlClient" />
</connectionStrings>
From Azure (All Settings >> Application Settings >> Connection Strings). The name of the connection string in Azure is DbConnectionString
Server=tcp:xxxxxxxxx.database.windows.net,1433;Initial Catalog=IMS;Persist Security Info=False;User ID=userName#xxxxxxxxx;Password=myPassword;MultipleActiveResultSets=True;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
Thank you for your help!!

Installing DotNetNuke : Database Connection Failing

I am trying to setup DNN on my local machine but having following error.
Installing DotNetNuke
Upgrade Error: ERROR: Could not connect to database specified in connectionString for SqlDataProvider
I have a SQL Server 2014 Express installed with custom login created.
I can login and access to database with same credentials using SQL Management Studio.
In web.config file, I have following lines for Database connection:
<connectionStrings>
<add name="SiteSqlServer" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=<dbName>;User ID=<UID>;Password=<PWD>" providerName="System.Data.SqlClient" />
<add name="SiteSqlServerAcuity" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=<dbName>;User ID=<UID>;Password=<PWD>" providerName="System.Data.SqlClient" />
<add name="AcuityEntities" connectionString="metadata=res://*/DAO.Model.SalesAcuity.csdl|res://*/DAO.Model.SalesAcuity.ssdl|res://*/DAO.Model.SalesAcuity.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=<dbName>;Persist Security Info=True;User ID=<UID>;Password=<PWD>;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient" />
and
<appSettings>
<add key="SiteSqlServer" value="Data Source=.\SQLEXPRESS;Initial Catalog=<dbName>;User ID=<UID>;Password=<PWD>"></add>
</appSettings>
I verified and changed connectionstrings in both sections as per so many references on internet but none of them worked.
Is there any other configuration needed? Or any change needed in web.config or Database configuration ?
THIS IS NOT A DFAULT DOTNETNUKE PACKAGE. ITS A CUSTOM PROJECT I AM TRYING TO SETUP.
There are a few things to consider, depending on the nature of the setup that you have.
Ensure that the Web Server can connect to the DB server. You may be able to connect to the server, but the web server itself cannot
Ensure that the user account being used has DBO rights, if DNN needs to upgrade etc it needs that level of permissions
This is more of a comment to #Mitchel Sellers answer, point 1. But it's a bit too much for a comment field.
Run the SQL Server Configuration Manager.
Go to "SQL Server Network Configuration".
Click "Protocols for <INSTANCE>".
In the right pane double click on "TCP/IP".
Make sure that "Enabled" is set to "Yes".
Go to the tab "IP Adresses".
For each IP, set the "TCP Port" to "1433", the "TCP Dynamic Port" to
"0" and "Active" and "Enabled" to "Yes".
With "IPALL" just set the port to "1433", leave the Dynamic as is.
Reboot or restart the SQL Server service.
With these steps I get a connection to the database from IIS using localhost
If you cannot find the Configuration Manager in the Start Menu, you can run it manually with C:\Windows\SysWOW64\mmc.exe /32 c:\Windows\SysWOW64\SQLServerManager12.msc

Login failed while connecting to database

I have created WPF application which has MDF file. When I added MDF file to my solutions folder It automatically created a connection string for me
<add name="Connection"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;Integrated Security=True;"
providerName="System.Data.SqlClient" />
I Deployed my application using SQL Server Compact (as described here). But When I run my Application I am getting exception
Cannot open database "C:\Users\Public\Desktop\MyDatabase.mdf" requested by the login. The login failed.
Login failed for user 'MY-PC\NAME'.
I am using Windows Authentication for my SQL Server
change your connection string as follows:
<add name="Connection"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=C:\Users\Public\Desktop\MyDatabase.mdf;persist security info=True;Integrated Security=SSPI;"providerName="System.Data.SqlClient" />

Categories

Resources