系统找不到指定的文件。

31
我在Stack Overflow上看到了许多与此错误相关的问题,但没有一个与表单相关。我在本地测试后才托管了我的应用程序服务器。我认为它可能工作了几分钟,但我不确定,因为我可能只是瞥了一下本地主机标签。然后它停止工作了。当我在服务器上进行更改时,我可能已经改变了某些内容。
我检查了连接字符串并尝试使用其他方式登录数据库,它是在线的。那么,有什么线索可能出错了吗?我不认为SQL Server只是不响应来自应用程序的请求,但如果您通过SSMS登录,则可用。
以下是我收到的错误信息。
“/”应用程序中的服务器错误。 系统找不到指定的文件
描述:在当前Web请求执行期间发生未处理的异常。请查看堆栈跟踪以获取有关错误的详细信息及其在代码中的位置的信息。
异常详细信息:System.ComponentModel.Win32Exception: 系统找不到指定的文件
来源错误:
在执行当前Web请求期间生成了未处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别。

[Win32Exception (0x80004005): 系统找不到指定的文件]

[SqlException (0x80131904): 在建立与 SQL Server 的连接时发生与网络有关或特定于实例的错误。无法找到服务器或无法访问。请验证实例名是否正确,并检查是否配置了允许远程连接的 SQL Server (提供程序: SQL Network Interfaces,错误: 52 - 无法定位本地数据库运行时安装。请验证已正确安装 SQL Server Express 并启用了本地数据库运行时功能。)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +5296071 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +558
System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5308555
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +920
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +225
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +37
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) +558
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) +67
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1052
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +167
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
1 retry, DbConnectionOptions userOptions) +143
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry) +83 System.Data.SqlClient.SqlConnection.Open() +96
System.Data.SqlClient.SqlProviderServices.UsingConnection(SqlConnection sqlConnection, Action
1 act) +79
System.Data.SqlClient.SqlProviderServices.UsingMasterConnection(SqlConnection sqlConnection, Action`1 act) +384
System.Data.SqlClient.SqlProviderServices.GetDbProviderManifestToken(DbConnection connection) +241
System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +26

[ProviderIncompatibleException: 提供程序未返回 ProviderManifestToken 字符串。]
System.Data.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) +170
System.Web.Providers.ModelHelper.GetStorageMetadata(String providerName, DbConnection connection, String ssdl) +35
System.Web.Providers.ModelHelper.CreateMetadataWorkspace(String providerName, DbConnection connection, String csdl, String ssdl, String msl

有人也遇到了这个错误,他们说他们正在使用错误的store连接到数据库,因此出现了错误。但是我在我的代码中只有一个store,没有其他的。

更新:

我找到了问题所在。它与成员资格相关。我的成员连接字符串出了问题,但我不知道是什么问题。我的应用程序需要注册,因此启用了身份验证。我没有更改默认设置。同时,在App_Data文件夹中发布了mdf文件。这里有一个类似的问题:将ASP.NET成员身份部署到Godaddy。但解决方案不明确,并且答案已被标记。我在连接字符串中添加了 并看到了错误:

应用程序配置中未找到连接名称'LocalSqlServer',或连接字符串为空。

那么我该怎么办呢?这个成员资格在本地运行得非常顺畅。

更新:

我也尝试了这个建议Godaddy ASP.NET成员资格数据库困扰。我删除了conn字符串并添加了名为“ LocalSqlServer”的字符串来使Godaddy满意。然后我删除并添加了以下内容,具有此connectionStringName-DefaultProfileProvider、DefaultMembershipProvider、DefaultRoleProvider和DefaultSessionProvider。仍然出现找不到指定文件的相同错误。


你的web.config文件中的"defaultConnectionFactory"是什么?我也可能遇到了同样的问题,我认为它与"defaultConnectionFactory"有关。 - Rob Lao
我遇到了几个问题并全部解决了。不确定是什么问题,但与defaultConnectionFactory无关。我认为这个错误是由于在配置中设置了TrustedConnection=true引起的。 - strider
我遇到了这个错误,发现我的一个连接字符串的名称是错误的。请检查名称以及实际字符串。 - Aaron Hodgson
10个回答

35

在建立到SQL Server的连接时发生与网络或特定实例相关的错误。找不到服务器或无法访问。文本

通常这样的问题与以下任何一个有关,需要进行检查:

  • 从Web服务器到数据库服务器的防火墙设置
  • 连接字符串错误
  • 启用适当的协议管道/ TCP-IP

尝试使用安装了SQL Server的系统上的SQL Management Server连接到SQL服务器,并从那里工作。注意错误日志中的信息。


1
似乎我不能在生产服务器上使用.mdf文件。SQL服务器需要配置成会员身份验证。我想这就是问题所在。 - strider
@strider,我们遇到了类似的问题?你的情况是什么问题? - emre nevayeshirazi
就像我在问题上面的评论中提到的那样,我遇到了多个问题,不太记得我是如何解决这个问题的。但我认为这个错误出现在我的配置文件中设置了TrustedConnection=true,而我又使用凭据进行登录。希望这可以帮到你。 - strider
3
我也遇到了这个问题。我的 "SQLSERVERAGENT" 服务已经停止了。当我启动了这个服务后,我的问题得到了解决。 - Majid Basirati
1
我的问题和@MajidBasirati一样。现在我通过如何启动SQL Server代理进行了修复,并将其设置为自动而不是手动。 - Cataclysm
显示剩余2条评论

10

在将我的项目发布到物理服务器后,我遇到了同样的错误。当我在VS2013上编译时,在我的计算机上我的Web应用程序可以完美地运行。当我在SQL Server Manager上检查连接字符串时,服务器上的一切也都正常工作。我还检查了防火墙(我关闭了它)。但是还是不起作用。我远程尝试使用管道/ TCP协议以及确切相同的用户/密码和实例名称等通过SQL Manager连接数据库,并且我发现一切正常工作。但是当我尝试打开网站时,我会遇到这个错误。有人知道第四个选项来解决这个问题吗?

注意:我的应用程序:ASP.NET 4.5(由VS2013),服务器:Windows 2008 R2 64位,SQL:MS-SQL WEB 2012 SP1 此外,其他Web应用程序在同一服务器上的其数据库上在Web浏览器中运行良好。


在煎熬了一天之后,我找到了我的问题的解决方案:

首先,我检查了所有日志和其他细节,但找不到任何东西。突然间我意识到:当我尝试使用直接连接到发布的数据库的连接字符串并通过VS2013在我的计算机上运行应用程序时,我发现它连接到了另一个数据库文件。我检查了本地目录,并找到了它。ASP.NET Identity没有像我在web.config文件中写的那样使用我的连接字符串。因此,由于此原因,VS2013正在创建或连接名为“DefaultConnection.mdf”的新数据库到App_Data文件夹中。然后,我在IdentityModel.cs中找到了解决方案。

我将代码更改为:

public class ApplicationUser : IdentityUser
{
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    //public ApplicationDbContext() : base("DefaultConnection") ---> this was original
    public ApplicationDbContext() : base("<myConnectionStringNameInWebConfigFile>") //--> changed
    {
    }
}

所以,最终,我重新构建并发布了我的项目,现在一切都正常了 :)


你是怎么获取备用连接字符串的?它是否可以从Azure门户中访问?在哪里? - Konrad Viltersten
我发布的应用程序偶尔会出现这个错误。我检查了ApplicationDbContext,发现它是不正确的。我进行了适当的更改,问题就解决了。再次强调,这个问题是间歇性的(考虑到这种错误应该是一贯性的),但希望我不会再遇到这个错误了。 谢谢! - Darrell Lloyd Harvey

3
如果您在部署 .Net MVC 网站应用程序后在 GoDaddy 上遇到此错误...并且您的 web.config 文件是绝对正确的...请右键单击数据项目,选择设置,并确保使用了正确的连接字符串连接到 GoDaddy 服务器。

谢谢,你的小评论对我很有帮助。 - Moshi

2

启动SQL Server代理,这应该可以解决你的问题。


1

我遇到了同样的问题-对我来说是SQL Server运行内存不足。释放一些内存解决了这个问题。


0

Server Error in '/' Application.

The system cannot find the file 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.

Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error:

     {
                   SqlCommand cmd = new SqlCommand("select * from tblemployee",con);
                   con.Open();
                   GridView1.DataSource = cmd.ExecuteReader();
                   GridView1.DataBind();

Source File: d:\C# programs\kudvenkat\adobasics1\adobasics1\employeedata.aspx.cs Line: 23

如果你的错误和我的一样..只需要这样做

在SQL Server对象资源管理器中右键单击表,选择属性,在常规选项的左下角有一个连接块,其中包含服务器和连接规范。在你的Web配置文件中,对于数据源=.或本地,请选择在属性中指定的名称所在的服务器..


0
最常见的原因可能是数据库连接字符串。您需要更改连接字符串 attachDBFile=|DataDirectory|file_name.mdf。主机名可能有问题,可能是(local)、localhost或.\sqlexpress。

0

当我启动我的ASP.NET应用程序时,出现了这个错误,在我的情况下,问题是SQL Server服务没有运行。启动它可以解决问题。


0

我在连接本地数据库时遇到了相同的错误。在我的情况下,在“服务”中启动 SQL Server (INSTANCE_NAME) 服务后,问题得到了解决。

enter image description here


0
考虑到 LocalDb 实例仅用于开发,当您部署最终结果时,LocalDb 不可用于生产服务器。 我认为您的连接字符串指向了一个 LocalDb 实例,您需要采取一些步骤将其转换为 SQL Server 数据库。 这不仅仅是复制一个 mdf 文件的问题。这可能因托管公司而异,但通常情况下,您需要创建现有数据库的备份(.bak 文件),然后将其还原到托管公司的 SQL Server 上。您应该询问他们在哪里可以找到有关将数据库部署到生产环境的说明。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接