0

i have a problem:

i am using .net core 3.1 WPF Application to connect to MSSQL SERVER 2016. The Code:

  SqlConnection conn = new SqlConnection("Server=MYSERVERNAME\\SQLEXPRESS;Database=MYDB;User ID=dbRead;Password=myPASSWORD;");
  conn.Open();

i searched a lot and found this: https://github.com/dotnet/SqlClient/issues/367 After a while i get a timeOut exception so i added Connect Timeout=60 and now the connection can be established, but maybe after >20 seconds.

The Server has also an old version of MSSQLSERVER installed 2012. (Because we upgraded from 2012 to 2016) This version has the instance MSSQL and with this instance and the same connection string (MYSERVERNAME\\MSSQL) i have no issues.

If iam using a .netframework application no error occures.

So i dont know what i have to do?

Maybe somebody had the same problem.

Thanks

UPDATE: After some research i found this:

Dot net Core – How to fix: TimeOut-Error to MSSQL 2017 (which does not happen with .Net 4.7.1)

Forcing to use named pipes by specifying np: qualifier in the server parameter in the connection string does the job

SqlConnection conn = new SqlConnection("Server=np:xxx.xxx.xxx.xxx\\SQLEXPRESS;Database=MYDB;User ID=dbRead;Password=myPASSWORD;");
  conn.Open();

1 Answers1

0

Data Source=[localhost];Initial Catalog=[database];Persist Security Info=True;User ID=sa;Password=[password]

remove 'sqlexpress'

make sure you are able to connect using proper creds w/ azure data studio or ssis.

---- Dotnet EF6 also if you are using EF6 (and have it setup) you can just add it to your scaffolding. makes life a bit easier if you are using the cli

dotnet ef dbcontext scaffold 'Data Source=[localhost];Initial Catalog=[database];Persist Security Info=True;User ID=sa;Password=[password]' Microsoft.EntityFrameworkCore.SqlServer -o 'Models/[database]/' docs: https://www.learnentityframeworkcore.com/migrations/commands/cli-commands

Ralph Fonz
  • 19
  • 2