Click here to Skip to main content
15,886,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am trying to set the 'user instance' to 'true' of local database in Visual Studio 2012 as it is needed in making the project as .exe, however, when I try to modify the connection, it gives me an error like: 

'The user instance login flag is not allowed when connecting to a user instance of SQL Server. The connection will be closed.'


What I have tried:

Here is the connection string:

    `SqlConnection sql = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Karen Kate\Documents\DateRangeTest.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True;Context Connection=False");`
Posted
Updated 21-Jun-18 18:26pm

1 solution

You can't do that in production: Only Sql Express supports attaching and local instancing as a development tool: the full version does not.
To use your DB on the full version of SQL (i.e. in production) you need to have your installation program create the DB under SQL instead of trying to attach it, then your app connects to that DB.

Why? Well, think about it. Your LocalDB instance is on the same machine as your code for dev, so SQL has access to your HDD. In production that is not what happens: SQL Server is installed on a dedicated machine and your app connects to that. That dedicated machine doesn't have any access to your file system and can't physically access the database file you are trying to use.
 
Share this answer
 
Comments
RyRen Infinity 22-Jun-18 1:47am    
@OriginalGriff How can I achieve that? Please. I really don't have a clue. This is my first time making a project into .exe
OriginalGriff 22-Jun-18 1:59am    
Start by looking at deployment:
https://www.google.co.uk/search?q=c%23+deployment+project&oq=c%23+deployment&aqs=chrome.3.69i57j69i58j0l4.7927j0j7&sourceid=chrome&ie=UTF-8
And then at this:
https://www.google.co.uk/search?q=create+DB+SQL+deployment+C%23&oq=create+DB+SQL+deployment+C%23&aqs=chrome..69i57.13560j0j9&sourceid=chrome&ie=UTF-8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900