Ahmad Abbasi Ahmad Abbasi - 3 months ago 112
ASP.NET (C#) Question

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

I have created A database inside visual studio and then add the connections string in my code

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


I am getting this exception when I try to fetch data from Database


[Win32Exception (0x80004005): The network path was not found]

[SqlException (0x80131904): 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: Named Pipes Provider, error: 40 - Could not
open a connection to SQL Server)]

System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity
identity, SqlConnectionString connectionOptions, SqlCredential
credential, Object providerInfo, String newPassword, SecureString
newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString
userConnectionOptions, SessionData reconnectSessionData,
DbConnectionPool pool, String accessToken, Boolean
applyTransientFaultHandling) +970

System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions
options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo,
DbConnectionPool pool, DbConnection owningConnection,
DbConnectionOptions userOptions) +802

System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool
pool, DbConnection owningObject, DbConnectionOptions options,
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 oldConnection, DbConnectionInternal&
connection) +191

System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection

Answer

why do you have a prentesis in your Data Source=LocalDB)?

try this:

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

Update change

Data Source= (localdb)\v11.0

To

Data Source= (localdb)\\v11.0