SQL网络接口,error:50 - 本地数据库运行时发生了错误。无法创建一个自动实例 [英] SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance

查看:4768
本文介绍了SQL网络接口,error:50 - 本地数据库运行时发生了错误。无法创建一个自动实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立具有在的App_Data MyDatabase.mdf 文件中的ASP.NET MVC 5 Web应用程序C>文件夹中。我有一个的LocalDB 实例安装了SQL Server 2014年防爆preSS。当我调试应用程序,并转到需要的数据库中,我得到以下错误的页面,我可以编辑使用服务器资源管理器数据库表,但是。

I am trying to build an ASP.NET MVC 5 Web Application which has a MyDatabase.mdf file in the App_Data folder. I have SQL Server 2014 Express installed with a LocalDb instance. I can edit the database tables using the Server Explorer, however when I debug the application and go to a page where the database is needed I get the following error.

建立SQL Server的连接时发生网络相关的或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:50 - 发生本地数据库运行时错误无法创建一个自动实例请参阅Windows应用程序事件日志错误的详细信息。

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 create an automatic instance. See the Windows Application event log for error details.

所以,我看着在事件查看器在应用,只有一遍一遍看到一条警告信息。

So I looked in the Event Viewer under Application and only see one Warning over and over again.

用于缓存COM pressed内容C指定的目录:\\用户\\用户1 \\ AppData的\\本地的\\ Temp \\ iisex preSS \\ IIS临时的COM pressed文件\\ Clr4IntegratedAppPool是无效的。静态COM pression被禁用。

The directory specified for caching compressed content C:\Users\User1\AppData\Local\Temp\iisexpress\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled.

所以,我试图重新启动服务器,仍然没有去。同样的错误50和以前一样。

So I tried rebooting the server, still no go. Same error 50 as before.

我在模式在那里我有一个叫做类创建的类<​​code>发表。

I have created an class under Models where I have a 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; }
    }
}

我也有一个控制器设置列出从 MyDatabase的的职位。

namespace MyApplication.Controllers
{
    public class PostsController : Controller
    {
        private MyDatabase db = new MyDatabase();

        // GET: Posts
        public ActionResult Index()
        {
            return View(db.Posts.ToList());
        }
    }

在我的的web.config 文件中的连接字符串看起来像这样...

In my web.config file the connection string looks like this...

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=(LocalDB)\v12.0;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

我试过的建议贴 href=\"http://www.aspneter.com/2013/08/error-50-local-database-runtime-error-occurred/\">但它没有工作。也试过<一个href=\"http://dyball.word$p$pss.com/2014/04/28/sql-2014-localdb-error-cannot-connect-to-locaidbv12-o/\">this.

I've tried the suggestion posted here but it didn't work. Also tried this.

我也注意到,我开始运行该应用程序后,MyDatabase的实例断开连接。如果我使用Visual Studio服务器资源管理器刷新数据库中,我可以查看表。

I also notice that the MyDatabase instance gets disconnected after I start running the application. If I refresh the database using Server Explorer in Visual Studio I can view the tables.

它是如何,我可以连接到数据库和Visual Studio 2013中编辑,但是当我调试应用程序不能连接到数据库?

How is it that I can connect to the database and edit it within Visual Studio 2013 but when I debug the application it cannot connect to the database?

推荐答案

重大更改到的LocalDB:适用于SQL 2014 ;看看这篇文章了,并尝试使用(的LocalDB)\\ mssqllocaldb 作为服务器名称连接到自动的LocalDB实例。

Breaking Changes to LocalDB: Applies to SQL 2014; take a look over this article and try to use (localdb)\mssqllocaldb as server name to connect to the LocalDB automatic instance.

文章还提及使用2012 SSMS的连接到2014的LocalDB。这使我相信,你可能已经安装了多个版本的SQL - 这使我指出这个SO回答的建议改变你的LocalDB实例的默认名称,以避免可能出现的前进其他版本不匹配的问题;提到不是问题的根源,但要提高潜在冲突的认识到安装在一台开发计算机上有多个版本的SQL可能导致......和东西,才能习惯去避免一些。

The article also mentions the use of 2012 SSMS to connect to the 2014 LocalDB. Which leads me to believe that you might have multiple versions of SQL installed - which leads me to point out this SO answer that suggests changing the default name of your LocalDB "instance" to avoid other version mismatch issues that might arise going forward; mentioned not as source of issue, but to raise awareness of potential clashes that multiple SQL version installed on a single dev machine might lead to ... and something to get in the habit of in order to avoid some.

值得一提的另一件事 - 如果你已经处于不可用状态得到您的实例由于与它修修补补,试图解决这个问题,那么它可能是值得重新开始 - 卸载,重新安装 - 那么尝试用 mssqllocaldb 值,而不是 12.0 键,看看是否能够修正您的问题。

Another thing worth mentioning - if you've gotten your instance in an unusable state due to tinkering with it to try and fix this problem, then it might be worth starting over - uninstall, reinstall - then try using the mssqllocaldb value instead of v12.0 and see if that corrects your issue.

这篇关于SQL网络接口,error:50 - 本地数据库运行时发生了错误。无法创建一个自动实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆