ADO.Net Connection Pooling with an MSSQL Account that is Disabled - asp.net

In our production environment we have a database that every 30 minutes is restored from a vendor's log shipping backup. When that restore happens, our SQL Auth account is disabled, the database is restored and the account is re-enabled.
A problem occurs when the connection pool is fresh and we attempt to connect to the disabled account. The bad connection is then pooled (I assume) and for the next 1 to 3 hours every connection throws a SQLException [SqlException: Login failed for user 'xxxxx'. Reason: The account is disabled.]
Even though, we can connect to the database via SSMS and an Application Pool reset fixes the issue.
Is there any fix other than to disable pooling?

Related

websphere liberty profile - add database connection errors to logs

I have a application deployed on liberty profile that connects to a db server over the network.
I'm trying to configure it so when connection time outs happen they are logged in messages or trace log files.
At the moment it just gives me an output like
Application xyz has not started in 30.004 seconds.
nothing to indicate why.... can anyone tell me how i configure it to output all DB related errors ?
A failure to connect to a database should not be related to whether or not your application starts. As any database access defined by application code would be running after the application has reported that it started.
I suspect there is a separate issue causing your application to not start. To confirm this theory you can comment out database access from your application and see if the app starts then.

Login failed for user "DOMAIN\USER" when connecting to DB in entity framework

I have an asp.net application running in IIS using the account which has access to my database. With windows authentication, I am able to log into this account in sql server manager and other things. In my connection string, I have Integrated Security=true, and the error message I get when loading a page using this connection string references the correct user. (Not 'IIS APPPOOL\ect...' like all the other instances of this question I have found on SO). Is there something else that can cause this issue? I just dont understand why I am able to log in with the same windows account in other applications.

Sharepoint 2010 DeleteExpiredSessions job is registered for the database

I am running SharePoint 2010. I keep getting "Expired sessions are not being deleted from the ASP.NET Session State database." warnings.
I connect to the server that hosts the ASP.NET Session State database, I start the SQL Server Agent service, and I confirm that a DeleteExpiredSessions job is registered for the database. I execute the stored procedure and a couple minutes later the warning is gone.
I come back the next day and I have the warning again. My question is there must be a way to automate this execution right? Either directly in SQL Server Management Studio or SharePoint Central Administration. I can't seem to find out how though.
You can re-create the "State Service Delete Expired Sessions" job definition by disable and re-enable the ASP.Net State Service via powershell, also you should verify that your account has the appropriate permissions in order to allow it to create SQL Agent jobs.
Disable-SPSessionStateService
Enable-SPSessionStateService –DefaultProvision
Here you can read a little more about this fix.

Distributed session reset

Our site is an ASP.NET MVC site, hosted on Azure and using Azure cache service as session provider. Below is our sessionstate configuration:
The cache in Azure is configured to use sliding expiration, with expiration period of 2 hours
Recently we have an issue of users suddenly being kicked out of the website. There is no exception during that time, except for SecurityException which we throw if user's not logged in. It seems that suddenly user's session is lost and ASP.NET assigns them a new session
As far as we know, since the site is using distributed session state provider, even if the server application pool is recycled, it should not kick out the user/cause session lost
May I know what are the possible causes for this issue? Is it due to distributed cache session provider or due to IIS or due to our site? How should we debug this issue?
Below is our production server IIS application pool setting
Thank you very much

Can't connect to database on server

I cannot connect to my SQL Server database when running app on server.
Everything runs fine when debugging but when I run on the server as ASPNET the user is unable to login.
I created the dataabse in a test project then simply connected to this db. My connection string is
Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Temp\Barry\fsr\FSR.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True
So this asp app runs on IIS 5 and when deployed the initial select works fine as my gridview that I have a binding to shows data but when I run the program (update the db) I hit the following:
[SqlException (0x80131904): Cannot open user default database.
Login failed.
Login failed for user 'hostxxxxx\ASPNET'.]
I am not creating this database programmatically as mentioned previously, simply connecting to an existing database.
The database is located on my c: - but I have added user ASPNET. How can I add this db to the program as a resource rather than reference a copy on c:?
My first question is this: If you have control of the server, why are you using an attached database. From:
AttachDbFilename=C:\Temp\Barry\fsr\FSR.mdf
There is no reason to attach if you can control the server. Attach the database to the actual instance in SQL Server, not with the bastardized version you have above. The bastardized version is useful on an ISP that does not give you access to SQL tools. Beyond that, it is more work than it is worth.
The second problem you have is authentication. There are a couple of ways to handle this. The easiest is set up a SQL user to access the database. If every user will have login credentials, you can keep the Windows Authentication method, but you have to turn off anonymous access, so every user GETS authenticated. As long as anon is a choice in IIS, it will default to anon and you will have issues. The third way is to impersonate a user for database access. I guess the fourth is open your database wide open, but I don't suggest destruction of security to make something "work".
If you have your database on a server, you need to use a server-based connection string - something like:
Data Source=servername\SQLEXPRESS;database=FSR;
Integrated Security=True;Connect Timeout=30;
Your user needs to have a login on the server, and a user in the appropriate database, in order to connect successfully.
See the ConnectionStrings.com web site for a huge list of possible connection strings - and what their settings mean and how you can change those.
You need to get into your database and assign the proper privileges to the account that is trying to access the database, which in this case looks like the built-in ASPNET account. Instead of the ASPNET account, you should use the NETWORK SERVICE account. You can change this through IIS.

Resources