0

I have a database on my local machine on SQL Server Management studio. SQL Server Management Studio

The database connection information is as follows. DB info

In my c# application, I have a connection string to connect to this database. I get an error though saying my connection string is incorrect. I have tried a number of different ones.

This is my function to connect to a database.

  public virtual void openConnection()
    {
        con = new SqlConnection();
        con.ConnectionString = "Server=DESKTOP-8UDMQUI\\WILLIAMSQL;Initial Catalog=team3db;TrustServerCertificate=true;";

        try
        {
            con.Open();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }

I have two \ in the server name because when I only have one, it has a red squiggle line under it throwing me an error on visual studio.

What should my connection string be? Note there is no password on this database.

1
  • If you want to use windows authentication in your conString. Then use con.ConnectionString = "Server=DESKTOP-8UDMQUI\\WILLIAMSQL;Initial Catalog=team3db;TrustedConnection=true;"; Commented Aug 8, 2019 at 20:56

1 Answer 1

2

Replace TrustServerCertificate = true; with Integrated Security = true

Sign up to request clarification or add additional context in comments.

1 Comment

The TrustServerCertificate keyword is valid only when connecting to a SQL Server instance with a valid certificate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.