0
votes

In my ASP.NET MVC application, I have created the new ADO.net entity object & pointed to (localDB)\mssqllocaldb (the connection string created automatically, table name tblProduct). After adding new controller (e.g. Product) with this entity and trying to access the index page, I'm getting an error.

Note : I am able to connect to the database in SQL Server Management Studio and also able to see the database in DataConnections in the Visual Studio server explorer

Error :

Exception message: 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 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. )

Application log in Windows 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.

Connection string

add name="productsContextV12" connectionString="metadata=res:///Models.products.csdl|res:‌​///Models.products.‌​ssdl|res://*/Models.‌​products.msl;provide‌​r=System.Data.SqlCli‌​ent;provider connection string="data source=(LocalDB)\mssqllocaldb;initial catalog=EMPDB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramew‌​ork"" providerName="System.Data.EntityClient" />

2
can you show us the connectionstring that is not working ? - GuidoG
<add name="productsContextV12" connectionString="metadata=res://*/Models.products.csdl|res://*/Models.products.ssdl|res://*/Models.products.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\mssqllocaldb;initial catalog=EMPDB2;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /></connectionStrings> - praveeen k
Can you edit our question and put the connectionstring there so it is readable ? Comments are not reader friendly for this - GuidoG

2 Answers

1
votes

issue got resolved after replacing "DataResouce=(LocalDB)\mssqllocaldb" with "Server=np:\.\pipe\LOCALDB#2XXXX\tsql\query" in ConnectionString .

Server name holds instance pipe name ,this can be found using command :

c:> sqllocaldb info mssqllocaldb . below is the image for details .

Thanks to GuidoG for ur quick response

command for the instance details:

enter image description here

0
votes

Your connectionstring is for LocalDB but the file is not set in the connectionstring. In stead it looks like you set the 'initial catalog' property to a database in some sql server.

For localDb you have to set the file containing the database, usually this is an MDF file.

This is what you need to do :

Create a textfile anywhere on your disk, and give it extension .udl
Now doubleclick on this file, the Microsoft datalink properties window will now open.
In this window configure everything until a click on 'test connection' succeeds.
Remember to choose

Attach a database file as a database name:

When this is done and 'test connection' returned success, then open the file in notepad and examen how the correct connectionstring should be in your case.