Celt67
Celt67

Reputation: 27

Connection string for local database not working

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.

Upvotes: 0

Views: 2268

Answers (1)

David Donari
David Donari

Reputation: 627

Replace TrustServerCertificate = true; with Integrated Security = true

Upvotes: 2

Related Questions