preSS数据库文件自动创建错误&QUOT

preSS数据库文件自动创建错误&QUOT

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

问题描述

我使用Visual Studio 2012创建一个MVC4互联网应用。我搬到从实体框架路程,现在我使用的是本地安装SQL Server 2008 R2的。

我改变了我的连接字符串在我的本地SQL Server实例来点:

 <&是connectionStrings GT;
    <添加名称=DefaultConnection的connectionString =数据源=;初始目录= NotesBoard;集成安全性= SSPI;的providerName =System.Data.SqlClient的/>
< /&是connectionStrings GT;

有在我的项目没有其他的连接字符串。这工作得很好,但现在我得到


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

说明:当前Web请求的执行过程中发生未处理的异常。请查看有关错误的详细信息的堆栈跟踪以及它起源于code。

SQLEx preSS数据库文件自动创建错误:结果
连接字符串指定本地SQL Server防爆preSS实例...


的奇怪的事情是,间歇性,这工作,然后又回到了它的破碎状态。

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

 公共类数据访问
{    公共无效的ExecuteNonQuery(字符串StoredProc,列表与LT;的SqlParameter>参数)
    {
        。字符串的ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings [DefaultConnection]的ToString();
        SqlConnection的CN =新的SqlConnection(ConnectionString中);        的SqlCommand厘米=新的SqlCommand(StoredProc,CN);
        cm.CommandType = CommandType.StoredProcedure;        FillCommandParameters(参数,厘米);        cn.Open();
        cm.ExecuteNonQuery();
        cn.Close();
    }    公共数据集执行(字符串StoredProc,列表与LT;的SqlParameter>参数= NULL)
    {
        。字符串的ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings [DefaultConnection]的ToString();
        SqlConnection的CN =新的SqlConnection(ConnectionString中);        的SqlCommand厘米=新的SqlCommand(StoredProc,CN);
        cm.CommandType = CommandType.StoredProcedure;        FillCommandParameters(参数,厘米);        SqlDataAdapter的大=新的SqlDataAdapter();
        da.SelectCommand =厘米;
        DataSet的DS =新的DataSet();        cn.Open();
        da.Fill(DS);
        cn.Close();        返回DS;
    }    私有静态无效FillCommandParameters(列表<&SqlParameter的GT;参数,的SqlCommand厘米)
    {
        如果(参数!= NULL)
        {
            如果(Parameters.Count大于0)
            {
                的foreach(在参数变量参数)
                {
                    cm.Parameters.Add(参数);
                }
            }
        }
    }
}


解决方案

重新部署时,我已经让我的MVC4网站同样的错误。我不能说这个问题的根本原因是什么,但它似乎是一些在浏览器缓存(也许是会话GUID)是当网站重新部署preserved出于某种原因,这将导致服务器端code到抛出这个奇怪的错误。

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

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.

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


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: 26 - Error Locating Server/Instance Specified)

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 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.

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);
                }
            }
        }
    }
}
解决方案

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.

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

08-29 03:39