“SQLExpress数据库文件自动创建错误”但DefaultConnect指向SQL Server 2008 R2 [英] "SQLExpress database file auto-creation error" but DefaultConnect pointing at SQL Server 2008 R2

查看:234
本文介绍了“SQLExpress数据库文件自动创建错误”但DefaultConnect指向SQL Server 2008 R2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2012创建一个MVC4 Internet应用程序。我已经离开了实体框架,我现在正在使用本地安装的SQL Server 2008 R2。

I am using Visual Studio 2012 to create an MVC4 Internet application. I've moved away from Entity Framework and I am now using a local install of SQL Server 2008 R2.

我将连接字符串更改为指向我的本地SQL Server实例:

I changed my connection string to point at my local SQL Server instance:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=NotesBoard;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

我的项目中没有其他连接字符串。这工作正常,但现在我正在获得

There are no other connection strings in my project. This worked fine, but now I am getting

建立网络相关或实例特定的错误与SQL Server的连接。服务器未找到或无法访问。验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供商:SQL网络接口,错误:26 - 定位服务器/实例指定错误)

描述:发生未处理的异常在执行当前Web请求期间。请查看堆栈跟踪以获取有关错误的更多信息及其在代码中的起始位置。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

SQLExpress数据库文件自动创建错误:

连接字符串指定本地Sql Server Express实例...

SQLExpress database file auto-creation error:
The connection string specifies a local Sql Server Express instance...

奇怪的是,间歇性地,这个工作,然后回到它的破碎状态。

The weird things is that, intermittently, this works, and then goes back to it's broken state.

更新:回答 Pawel 的问题:
我有以下类,从我所有的控制器引用:

Update: To Answer Pawel's question: I have the following class which is referenced from all my controllers:

public class DataAccess
{

    public void ExecuteNonQuery(String StoredProc, List<SqlParameter> Parameters)
    {
        String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
        SqlConnection cn = new SqlConnection(ConnectionString);

        SqlCommand cm = new SqlCommand(StoredProc, cn);
        cm.CommandType = CommandType.StoredProcedure;

        FillCommandParameters(Parameters, cm);

        cn.Open();
        cm.ExecuteNonQuery();
        cn.Close();
    }

    public DataSet Execute(String StoredProc, List<SqlParameter> Parameters = null)
    {
        String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString();
        SqlConnection cn = new SqlConnection(ConnectionString);

        SqlCommand cm = new SqlCommand(StoredProc, cn);
        cm.CommandType = CommandType.StoredProcedure;

        FillCommandParameters(Parameters, cm);

        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cm;
        DataSet ds = new DataSet();

        cn.Open();
        da.Fill(ds);
        cn.Close();

        return ds;
    }

    private static void FillCommandParameters(List<SqlParameter> Parameters, SqlCommand cm)
    {
        if (Parameters != null)
        {
            if (Parameters.Count > 0)
            {
                foreach (var Parameter in Parameters)
                {
                    cm.Parameters.Add(Parameter);
                }
            }
        }
    }
}


推荐答案

在重新部署时,我的MVC4网站上出现同样的错误。我不能说这个问题的根本原因是什么,但似乎是在浏览器中缓存的东西(可能是会话Guid)在该站点重新部署时被保留,并且由于某种原因导致服务器端代码抛出好奇的错误。

I have been getting the same error on my MVC4 site when redeploying. I can't say what the root cause of the issue is but it appears to be that something cached in the browser (perhaps the session Guid) is preserved when the site is redeployed and for some reason this causes the server side code to throw this curious error.

关闭并重新打开浏览器似乎清除缓存,然后网站按预期工作。这可能解释了这个问题的间歇性。

Closing and reopening the browser seems to clear the cache and then the site works as expected. This might explain the intermittent nature of the issue.

这篇关于“SQLExpress数据库文件自动创建错误”但DefaultConnect指向SQL Server 2008 R2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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