I'm starting a DEV on NET Core 2.2, I have a local DB in SQL Server Express that I'm trying to connect, well, I wrote the following code.
This razor is pulling from Startup Class the Connection string returning successfully:
@{
Startup s = new Startup(null);
string connstring = s.ConnectionStringReturn();
var dbh = new BDHandlercs(connstring);
}
// This code will display the connection string on the html page for testing purposes
// @string.Format("Connstring: {0}", connstring);
// Returning
// Connstring: Server=.\sqlexpress|Database=PV_REPUESTOS|User id=SystemUser|Password=Service1023;
After knowing what it loads, I ran the method like this:
dbh.GetConnection();
public SqlConnection GetConnection()
{
SqlConnection connection = new SqlConnection(this.ConnectionString);
if (connection.State != ConnectionState.Open)
connection.Open();
return connection;
}
Nevertheless I got the following:
An unhandled exception occurred while processing the request.
Win32Exception: The network path was not found
Unknown locationSqlException: 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, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, bool applyTransientFaultHandling)
Which doesn't make sense to me, I can connect using SQLCMD, SQL Server Management Studio and everything, I have a WCF service that connect as well to the DB, I have the named pipes and the ports open, I think that is a problem on NET Core, any thoughts?
|in your connectionstring? I wasn't aware pipe was a delimiter for anything but an entity framework resources. Have you tried replacing the pipes with semicolons? - Charleh