C
C#5mo ago
PjotrH

Dotnet API and local DB connection string

Hey there, I can't for the life of me connect my Dotnet API to my local MSSQL server. It works as it should when I'm connecting to my Azure SQL Database and querying data, so it's not a code problem. Outside of the Dotnet API I have successfully connected to my local db with these methods: - DBeaver, sa user and password (URL) - DBeaver, windows authentication (URL) - DBeaver, sa user and password (Host) - DBeaver, windows authentication (Host) - Visual Studio SQL server object explorer ...So the server is working as it should. I've tried a few dozen different connection strings. I've tried the connection string generated by SQL server object explorer. Judging by search results, it seems everyone on the internet has a different "default connection string" that works fine. What should this thing even look like? More info: I've enabled TCP connection on localhost:1433 in SQL Server Config Manager. When I installed the server, I enabled mixed login (windows or username/pwd)
4 Replies
PjotrH
PjotrHOP5mo ago
For reference, this is the connection string VS SQL object explorer gives me: Data Source=DESKTOP-5BORAFJ;User ID=sa;Password=**;Connect Timeout=30;Encrypt=False;Trust Server Certificate=True;Application Intent=ReadWrite;Multi Subnet Failover=False (Tried it, doesn't work) And this is the JDBC string I'm using in DBeaver with user sa/password: jdbc:sqlserver://;serverName=localhost;databaseName=master (this does work)
Jimmacle
Jimmacle5mo ago
what is the actual error you're getting? try Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;Trust Server Certificate=true;
PjotrH
PjotrHOP5mo ago
@Jimmacle if I use Server=DESKTOP-5BORAFJ, I get this: 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) Same with Server=localhost ---> System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known Server=localhost,1433 produces this: 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: 40 - Could not open a connection to SQL Server) So, closer? But still not working. Something wrong with the server config? (If that's the case why can I connect from two other applications?) Tried another couple of variants. All error: 40. So maybe the first one, Server=DESKTOP-5BORAFJ, is closer oh, and a TCP connection test to localhost -Port 1433 in powershell is positive
jcotton42
jcotton425mo ago
@PjotrH what if you use localhost instead of your computer's name? oh, you did
Want results from more Discord servers?
Add your server