Trouble Connecting to Database
I'm using Dapper and SqlClient but I keep getting this error:
Unhandled exception. Microsoft.Data.SqlClient.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: TCP Provider, error: 35 - An internal exception was caught)
here is the code:
11 Replies
the port is running and I can connect through the terminal to localhost:5432 using that login
See how the error mentions "SQL Server" everywhere?
Your database seems to be PostgreSQL
but how does it get the port then
?
like how does it connect if it doesn't know the address of the server
Well that's the problem
It does not connect
you need to use Npgsql, not Microsoft.Data.SqlClient
You need the Npgsql nuget and use
NpgsqlConnection
instead of SqlConnection
ah
the ADO.NET providers are database specific
I see my bad
I'll try that out then