Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed - asp.net

I've attempted to add a "service based data base" (.mdf) to a project in an asp .net application. From there I've proceeded attempted to create an entity framework model file (.edmx).
When doing so I get the error:
An error occurred while connecting to the database. The database might be unavailable. An exception of type 'System.Data.SqlClient.SqlException' occurred. The error message is: 'Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.'.
I've got SQL Server 2008 R2 Express edition installed on my machine.
Any ideas would be most appreciated.

I have got the same error, it's fixed after the following change.
Deleting the folder C:\Users\User\AppData\Local\Microsoft\Microsoft SQL Server Data worked for me in Windows 7. Have to restart VS after deleting the folder.

See this answer, which might work for you.
Based on your connection string, you might need to add "User Instance" attribute to it.

I had this exact same problem with a C# Console App that was utilizing an .mdf file.
The issue disappeared once I granted NETWORK SERVICE full access to my root-level Visual Studio project directory (and sub directories).
Solution Details: Problems with SQL Server Express user instancing and ASP.net Web Application Projects

I was facing same issue in VS 2019. if anyone still facing same issue then please make sure you have/do following things:
1. you should have Sql server Express installed on your m/c
2. should have SSDT installed in VS (in VS 2019- name sure to check this component while installing) for previous version; i guess you have to add this externally
3. add 'User Instance = True' to your connection string
and one more thing and I think its optional - open VS and SQL in administrative mode

If you build your own custom membership solution, do not forget to add this line to your Web.config's AppSettings section:
<add key="enableSimpleMembership" value="false" />
otherwise you'll get the same error message

I have same issue, but it only happens when I reboot the PC and run the application from a fresh start. If I then attempt to re-start the application (wo rebooting), it does connect and I have full access to the database. I tried to change the connection string with a long timeout (600, 6000, 60000), but that made no difference. Here is the connection string:
"
"

Related

Can't Access SQLite DB on Azure Web App

I have created an ASP.NET MVC web app which uses an SQLite database under EF6.
The app works fine in VS. The database is included in the project in the App_Data folder. When I publish to Azure (or an IIS test server on the LAN) I get an error. The Azure instance is showing an HTTP 500 error, and it only happens on views which require database access to load. Other than that it works fine. The IIS test server shows an error saying unable to open database file. I tried loosening file permissions on the .db file on the IIS instance, but nothing changed. I'm not sure how to go about doing anything on the Azure instance.
Can someone please assist me with debugging a SQLite connection problem on Azure/IIS?
Details
VS 2015 Enterprise
Azure app services (free tier, production server)
SQLite3 database
IIS on Windows Server 2012R2 (test server)
I have tried all sorts of combinations of connection strings:
setting a connection string to the D:/xxx/xxx path in Azure Portal
modifying the connection string in the deployment profile in VS (replaces value in web.config upon deployment)
just leaving it all the same
Nothing has worked or even changed the error. Perhaps one of those configurations is able to access the file but simply can't open it (which is sort of what the IIS error suggests, I think). Even then, how do I go about finding out?
EDIT
On the IIS test server I discovered that the entire problem was that the connection string in Web.config was wrong. I manually edited it on the server and it fired right up. I'm still not sure how to correct the path on the Azure server, nor how to correct my deployment settings in VS to inject the correct path. Thoughts along those lines are still appreciated.
EDIT 2
I've also found that each time I hit a page requiring DB access, I see this error show up in the application logs on Azure:
2017-01-03T20:25:32
System.ApplicationException: The trace listener AzureBlobTraceListener is disabled. ---> System.InvalidOperationException: The SAS URL for the cloud storage account is not specified. Use the environment variable 'DIAGNOSTICS_AZUREBLOBCONTAINERSASURL' to define it.
at Microsoft.WindowsAzure.WebSites.Diagnostics.AzureBlobTraceListener.RefreshConfig()
--- End of inner exception stack trace ---
After some abysmally slow debugging sessions, I finally remembered that in toying around I had set a connection string value in the Azure portal.
Apparently whatever value is set in the Azure Portal overrides (at runtime?) the values in the Web.config file
I simply deleted the connection string from the Azure Portal (your app/Application Settings/Connection Strings) and it worked. The final connection string looks like this:
<add name="yourThingEntities" connectionString="metadata=res://*/cadb_SQLite.csdl|res://*/cadb_SQLite.ssdl|res://*/cadb_SQLite.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=D:\home\site\wwwroot\App_Data\yourSQLiteDBFile.db"" providerName="System.Data.EntityClient" />
To get the Web Deploy working in VS, you'll need to edit the publish profile to have a connection string matching the format
data source=D:\home\site\wwwroot\App_Data\yourSQLiteDBFile.db
Apparently not many people use SQLite for web apps, and most people should not. If you ever expect more than one user for your website at a time, you shouldn't fix SQLite, you should convert to SQL Server CE or just full-blown SQL Server which Azure will take care of for a paltry $5/mo. Choose wisely!

ASP.NET MVC Entity Framework application is using wrong SQL connection string

I have an ASP.NET MVC5 web application that was originally created using VS2013 and uses Entity Framework 6 Code First, with data migrations. It has been working fine (in production) for almost a year and has been re-deployed numerous times, from Visual Studio, using Web Deploy.
Today, I opened the solution in VS2015 and redeployed a known working version of the codebase to production without any problems. However, after deployment, the production website suffered from the problems described in this article, which I solved by applying author's the recommended fixes.
After applying these fixes, I now have a new problem: an exception that suggests that the application is trying to access the database using the wrong connection string:
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
Within the details of the exception page, the cause of the problem is clarified:
The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory.
I'm puzzled by this because the application has a dedicated SQL Server instance that is accessed using a regular connection string. I've checked the Web.config generated by Web Deploy and it seems to be intact. It contains a named connection string that correctly references the production SQL Server instance, and the code (which hasn't changed) correctly instantiates an Entity Framework ApplicationContext using the named connection string.
Does anyone have any idea why this application now expects to create its own SQL Server instance or what I can do to debug this problem?
Many thanks for your suggestions,
Tim
A few things you can try before making the web deploy:
Check if the project that contains the connection string declaration (web.config) is setted as the 'startup project'.
Rebuild the solution in release mode.
In the Publish Web wizard, in Settings, expand File Publishing Options and check 'Remove additional files at destination' and 'Exclude files from App_Data folder'

SQL Database error generated during IIS deployment

my asp.net application runs successfully in development server of visual studio. but when i deploy my application in IIS it generates the error as follows
Failed to generate a user instance of SQL Server due to failure in
retrieving the user's local application data path. Please make sure
the user has a local user profile on the computer. The connection will
be closed.
what are the necessary changes that i should do in my application. also guide me how to deploy my database on IIS.
What is your connection string?
More specifically, I am wondering if you are using a .mdf file as your database.
If this is the case, you need to ensure that your web application has write-permissions within the App_Data folder of your website.
It is hard to say exactly without seeing your connection string, but possibly this KB article will help. It relates to SQLExpress and the error you are seeing.
http://support.microsoft.com/kb/2002980

WCF Data Service, EDMX Entity Data Model, Oracle 11 database, not deploying to IIS

I am implementing a WCF Data service that implements the following method:
http://debugmode.net/2010/06/13/introduction-to-wcf-data-service-and-odata/
I've installed the following beta ODAC component:
http://www.oracle.com/technetwork/topics/dotnet/downloads/oracleefbeta-302521.html
When I run the solution in Visual Studio 2010, it returns data perfectly, when I deploy the application to IIS 7, it throws the following exception:
The underlying provider failed on Open.
I checked the connection strings in both, they are set up identically, the only thing I can think of, which I believe is a non-issue is that the Oracle client components install the TNSNAMES.ora and sqlnet.ora in the following location:
There are 2 for the username
C:\app\<username>\product\11.2.0\client_1\Network\Admin
C:\app\<username>\product\11.2.0\client_2\Network\Admin
and there's one for oraclebase -
C:\app\oraclebase\product\11.2.0\client_1\Network\Admin
I've copied the working files to all the right locations, in fact, I can connect perfectly fine via SQL Plus
My gut tells me that the application pool/identity that IIS is running under isn't loading the correct configuration values, but, I changed the app pool account to run under -my- account.
Here's the connection strings that are being used from the ASP.NET application (in case it helps)
metadata=res://*/ENTITY_NAME.csdl|res://*/ENTITY_NAME.ssdl|res://*/ENTITY_NAME.msl;provider=Oracle.DataAccess.Client;provider connection string="DATA SOURCE=DATABASENAME;PASSWORD=PASSWORD;PERSIST SECURITY INFO=True;USER ID=USERNAME"
By the way, I have another WCF data service on the same server, it's pointing to a SQL instance and pulling data just beautifully, there was an issue with the identity on that app pool, but that was resolved.
Anyone know what it might be?
Note: I am also doing a connection.open() and connection.close() on the entities in code.
I resolved this issue. The problem was that my application pool wasn't configured to enable 32-bit applications to run. The ODAC component is 32-bit.
In a round about kinda way, this post was helpful too, to help understand the various moving parts in configuring Oracle to connect.

asp.net SQL Database File Error

We're getting the following error when trying to establish a connection to a database file in the project:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
Any ideas on how we can fix it?
Thanks in advance!
http://jeremywadsworth.com/Default.aspx?blogentryid=56 has one possible fix.
http://forums.asp.net/t/1377174.aspx also has further discussion on the topic.
Hope that helps.
--
One more idea. I think I've encountered something like this when using Visual studio to create and access my database. You can detach your database file from visual studio and then directly attach it to your SQL server. I can't remember if the problem manifested in the same way or not but this should get you around the user instance issue. If this doesn't apply let me know and I'll see if i can come up with anything else.
If you are using IIS as the server,then this occurs because the server takes default asp.net database.
In IIS server,create your own application pool and run your app on that instead of using the default pool.
Check the permissions.Give full access control rights.
Also,
go to SQL server configuration>properties. Select local system in the built-in app.. And your new pool should also have local system selected.
This fixed the problem for me. Hope it works for someone here.
PS: If you are trying to making connectivity in Visual studio for android application,then close the visual studio before running it on android as the process wont complete if visual studio is open and will result into error.
SQL Express file attach starts a new 'user instance' SQL Server. This involves a new master/model/msdb/tempdb set of files that are created in the user settings data folder. also the startup of the new 'user instance' can take up to several minutes on extreme cases.
This MSDN article on SQL Server 2005 Express Edition User Instances cover in detail the process and luckly it has some Common Issues and fixes. The most common failure is due to access rights over the user settings copied files. You will usualy get details about the failure in your NT event log (ie. why did the child instance not start).
We got over this by copying the database from my machine to my team-mate's.

Resources