29

I am getting this Exception When I am trying to access database from C#.

My Connection String is

Data Source=(localdb)\v11.0;integrated security=true;User Instance = true;AttachDbFileName=C:\Users\UserName\Desktop\DB\TestDB3.mdf

Exception is

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

crthompson
  • 15,653
  • 6
  • 58
  • 80
Siddharood
  • 908
  • 1
  • 12
  • 24

2 Answers2

49

LocalDB instances are all "User Instances", and there's no need to specify User Instance=true in your connection string, in fact it is not even supported (as you can see). Just remove this part and it's going to work fine.

Krzysztof Kozielczyk
  • 5,887
  • 37
  • 28
  • 2
    Seems self explanatory when you put it like that. I think my issue was cause by switching between IISExpress and Local IIS. This fixed it though – ste-fu May 22 '15 at 15:12
3

Just to add some more information. If some how this doesn't work for you and it still complains that its not able to locate server. You will be required to set following two attributes on your application pool identity in applicationHost file

<add name="DefaultAppPool">
            <processModel identityType="NetworkService" loadUserProfile="true" setProfileEnvironment="true" />
        </add>

where these two attributes are required to make sure your account can start LocalDB server.

Mazhar Qayyum
  • 630
  • 7
  • 22