System.ComponentModel.Win32Exception:未找到网络路径错误

我在Visual Studio中创建了一个数据库,然后在我的代码中添加连接字符串

string connString = "Data Source=(LocalDB)v11.0;AttachDbFilename="D:POSApp_DataPOS.mdf";Integrated Security=True";

当我尝试从数据库获取数据时,我收到了这个异常

[Win32Exception(0x80004005):未找到网络路径]

[SqlException(0x80131904):建立与SQL Server的连接时发生网络相关或实例特定的错误。 服务器未找到或无法访问。 验证实例名称是否正确,并将SQL Server配置为允许远程连接。 (提供程序:命名管道提供程序,错误:40 - 无法打开与SQL Server的连接)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,SqlCredential凭证,Object providerInfo,String newPassword,SecureString newSecurePassword,Boolean redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData,DbConnectionPool池,字符串accessToken,布尔applyTransientFaultHandling)+970
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo,DbConnectionPool池,DbConnection拥有连接,DbConnectionOptions userOptions)+802
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool池,DbConnection owningObject,DbConnectionOptions选项,DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)+38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)+682
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions userOptions,DbConnectionInternal oldConnection)+89
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&connection)+426
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1重试,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal&connection)+191
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(的DbConnection


为什么你的Data Source = LocalDB中有一个prentesis)?

尝试这个:

string connString = "Data Source=(LocalDB)v11.0;AttachDbFilename="D:POSApp_DataPOS.mdf";Integrated Security=True";

更新更改

Data Source= (localdb)v11.0

Data Source= (localdb)v11.0
链接地址: http://www.djcxy.com/p/56729.html

上一篇: System.ComponentModel.Win32Exception: The network path was not found Error

下一篇: Failure to connect my web page to a database