c# - SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance -
i trying build asp.net mvc 5 web application has mydatabase.mdf
file in app_data
folder. have sql server 2014 express installed localdb
instance. can edit database tables using server explorer, when debug application , go page database needed following error.
a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: sql network interfaces, error: 50 - local database runtime error occurred. cannot create automatic instance. see windows application event log error details.
so looked in event viewer under application
, see 1 warning on , on again.
the directory specified caching compressed content c:\users\user1\appdata\local\temp\iisexpress\iis temporary compressed files\clr4integratedapppool invalid. static compression being disabled.
so tried rebooting server, still no go. same error 50 before.
i have created class under models
have class called post
.
namespace myapplication.models { public class post { public int id { get; set; } public string title { get; set; } public string content { get; set; } } public class mydatabase : dbcontext { public dbset<post> posts { get; set; } } }
i have controller
setup list posts mydatabase
.
namespace myapplication.controllers { public class postscontroller : controller { private mydatabase db = new mydatabase(); // get: posts public actionresult index() { return view(db.posts.tolist()); } }
in web.config
file connection string looks this...
<connectionstrings> <add name="defaultconnection" connectionstring="data source=(localdb)\v12.0;attachdbfilename=|datadirectory|\mydatabase.mdf;integrated security=true" providername="system.data.sqlclient" /> </connectionstrings>
i've tried suggestion posted here didn't work. tried this.
i notice mydatabase instance gets disconnected after start running application. if refresh database using server explorer in visual studio can view tables.
how can connect database , edit within visual studio 2013 when debug application cannot connect database?
breaking changes localdb: applies sql 2014; take on article , try use (localdb)\mssqllocaldb
server name connect localdb automatic instance, example:
<connectionstrings> <add name="productscontext" connectionstring="data source=(localdb)\mssqllocaldb; ...
the article mentions use of 2012 ssms connect 2014 localdb. leads me believe might have multiple versions of sql installed - leads me point out this answer suggests changing default name of localdb "instance" avoid other version mismatch issues might arise going forward; mentioned not source of issue, raise awareness of potential clashes multiple sql version installed on single dev machine might lead ... , in habit of in order avoid some.
another thing worth mentioning - if you've gotten instance in unusable state due tinkering try , fix problem, might worth starting on - uninstall, reinstall - try using mssqllocaldb
value instead of v12.0
, see if corrects issue.
Comments
Post a Comment