Local IIS unable to connect local database - c#

I am using a db from (localdb)\V11.0 server and able to connect successfully when using IIS express from VS2013, but when deployed in LocalIIS, it gives me an error below -
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible.
In order to fix that I have updated applicationHost.config file as below
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Now, though database is not connected, it has displayed a home page, but all data-driven dropdown values are empty. I have also tried changing Application pool to LocalSystem but website unable connect db. Is there any specific area that I need to investigate?

To get local db running with IIS on my machine, I followed the guidance in this msdn blog
The solution that worked best for me was to configure IIS application pools to run as my windows user.
This is done via the IIS interface. In the "Application Pools" section, right click on one (or more) and choose "Advanced Settings". Choose "Identity" and "Custom" then enter your username and password.

You can check if Application Pool / Local System has an account to access the database. There is also an option to user impersonate user https://support.microsoft.com/en-us/kb/306158
example:
<identity impersonate="true" userName="accountname" password="password" />

Related

Login failed for user 'IIS APPPOOL\test.bata.com'. when launching ASP.NET Core application from ASP.NET

I am deploying my ASP.NET application on IIS. Everything works well when I run it on Visual Studio with IIS Express but when I use IIS, the event viewer shows this error.
I added a login on SQL Server but still get the same error
Any idea on what I could be missing?
Grand DB_Owner permission for "IIS APPPOOL\test.bata.com". also check the connection string in web.config file
You can try to use custom identity in application pool with the windows user name password and use this string in web.config file.
<add name="umbracoDbDSN" connectionString="data source=YOUR_SERVER_NAME;database=nrc;Integrated Security=SSPI;persist security info=True;" providerName="System.Data.SqlClient" />
For more detailed steps you can refer to this link: https://forums.iis.net/t/1249665.aspx

ASP.NET Access denied for user (using password: NO) after deploy with msbuild/msdeploy

I'm setting up ci-deployment using jenkins for multiplice ASP.NET MVC 5 EF CF application with MySQL-Database on a Windows Server 2012 R2 node. The app gets compiled first using msbuild and then published on IIS with msdeploy. ConnectionStrings will be replaced using the -setParamFile parameter, which works.
The problem: After calling the app on the target server, I get the following MySQL error:
MySql.Data.MySqlClient.MySqlException: Access denied for user 'myUser'#'myIp' (using password: NO).
The MySQL-Doc say that this means the clinent had tried to connect without password.
This is really confusing me because my ConnectionString certainly contains a password! In the Web.config from the folder of the IIS-App it looks like this:
<add name="MyContext" connectionString="Server=SERVERIP;Database=MYDBNAME;Uid=DATABASEUSER;Pwd=PWD;Convert Zero Datetime=True;" providerName="MySql.Data.MySqlClient" />
Which is valid, because the app is running fine on local debugging and a Windows Server 2012 R2 based testsystem, where I deployed the app using Web-Publishing function of Visual Studio.
I have the suspicion that my Web.config gets overwritten, but can't find out where and why. I took a look in the local Machine.config file of the target-server, but in contrast to another thread with nearly the same problem this isn't containing my ConnectionString (And I even can't imagine why this should gonna happen).

Hosting ASP.NET Web App on IIS DB connection problems

I have used IIS before, but I've never used a database and I've never done a web app. I did the same steps for putting a site onto IIS and everything works EXCEPT for when I go to a page that has a DB connection on it. I've tried a lot and this is all I get.
A network-related or instance-specific error occurred while establishing a >connection to SQL Server. 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
Windows Application Event Log:
Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user.
This was built in Visual Studio and I have a SQL Express DB.
I posted my connection strings, any help is greatly appreciated.
I have added this to my applicationHost.config:
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
And now I get:
An attempt to attach an auto-named database for file |MY DB1 FILE| failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB1.mdf;Initial Catalog=aspnet-ICCAA_VIZIER-20150223043129;Integrated Security=True" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\DB2.mdf;Integrated Security=True;Connect Timeout=30" providerName="System.Data.SqlClient"/>
I was able to figure it out. I changed all my data connections to .\SqlExpress. Which led me to another error of:
Login failed for user ‘NT AUTHORITYNETWORK SERVICE‘
To fix this I followed this guys article to figure it out.
Login Failed For user NetworkService

Issue in deploying ASP.NET MVC Application on the IIS Server

I am trying to deploy a MVC Application on the IIS server.
I have shared the sqllocaldb using command prompt and created a Private LocalDB instance with name IIS_DB
I have also changed the connection string in my Web.Config file to
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\.\IIS_DB;Initial Catalog=aspnet-MvcApplication26-20141226150050;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication26-20141226150050.mdf" providerName="System.Data.SqlClient" />
As of now I can view the Home Page when I click on Browse from the ISS Manager.
But when I click on the Register/Login hyperlink, I get the following error
Cannot attach the file 'C:\inetpub\wwwroot\MvcApplication26\App_Data\aspnet-MvcApplication26-20141226150050.mdf' as database 'aspnet-MvcApplication26-20141226150050'.
I finally solved this by manually copying the APP_Data folder from Visual Studio to the my application directory on the IIS server
After sharing the database here is what you have to do
Go to visual studio => databaseexplorer => add connection
For the server name enter (LocalDb).\IIS_DB then right click on the connection and choose new query and execute this command:
create login [IIS APPPool\DefaultAPPPool] from windows;
exec sp_addsrvrolemember N'IIS APPPool\DefaultAPPPool, sysadmin

Windows Azure Web Service, Fails to Connect to SQL Database

I'm working on this for some time and I have no idea anymore what to do.. so here is the problem.
I've got a Azure Webservice, which works perfectly localy. It should connect to a Azure SQL Database (I use the same ConnectionString for debug AND azure.. so it SHOULD be right)
Using IntelliTrace, I find these Errors:
Requested registry access is not allowed.
System.IO.FileNotFoundException Could not load file or assembly 'EntityFramework, Version=6.0.0.0, Culture=Neutral....
System.Data.Entity.Core.ProviderIncompatibleException
System.Data.SqlClient.SqlException A network-related or instance-specific error occured while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct... (This about 50 times)
System.Threading.WaitHandleCannotBeOpenedException No handle of the given name exists.
System.Security.SecurityException Requested registry access is not allowed
Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironmentException error
System.Threading.WaitHandleCannotBeOpenedException No handle of the given name exists.
(Exception stack, top newest, bott oldest)
In my web.config I setup EF and ConnectionString like this:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="EntityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false"/>
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=SERVER.database.windows.net;Database=LeagueMetaDatabase;User ID=USER#ksew7pk8ad;Password=PW;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
I also deactivated "Specific Version" for the EF assembly and activated "Copy Local".
I checked in the bin folder of the service on the server, the dll is there.
The service uses a lot of async, but as already said it works localy.. I also installed .NET 4.5.1 on the server just to be sure that is not the problem
// Edit
First of all, thanks for all the help so far!
I tried narrowing the problem down.. reconstructing the hole project and trying to find what does not work. It seems that async Tasks can NOT read the ConnectionString in the Web.config on the Azure Server Cloud. In the emulator, it works. I hardcoded the ConnectionString into the Context and it is working this way.
Anyone can tell me what creates this behaviour and how I can put it back into the Web.config?
How is your solution deployed to Azure? Are you using a Cloud Service or Web Site? If you're running an Azure Web Site the problem might be related to your connection string name being the same in both the web.config and also your Azure Web Site. If this is the case you might want to try renaming the connection string defined in the Azure Management Portal for you web site. This can be done through the Configure management page.
Hope this helps.
Are the DB & Cloud Service in same data center? If not, link your resources via the Azure control panel and/or make sure that you have enabled "allow azure services to connect" in the DB configure section.
Also, make sure your SERVER connection specifies "tcp" - The Windows Azure SQL Database service is only available with TCP port 1433. To access a SQL Database database from your computer, ensure that your firewall allows outgoing TCP communication on TCP port 1433 (from Guidelines for Connecting to Windows Azure SQL Database). If you grab the ADO connection string from the DB dashboard page, you should see:
Server=tcp:{your_servername}.database.windows.net,1433;Database={your_database_name};User ID={your_userid};Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
First of all, thanks for all the help so far!
I tried narrowing the problem down.. reconstructing the hole project and trying to find what does not work.
It seems that async Tasks can NOT read the ConnectionString in the Web.config on the Azure Server Cloud. In the emulator, it works. I hardcoded the ConnectionString into the Context and it is working this way.
Anyone can tell me what creates this behaviour and how I can put it back into the Web.config?

Categories

Resources