Your connection string is malformed. My gut instinct is that your password contains a quote, equal or semicolon which is throwing off the connection string parser resulting in the odd error. However I also notice you don't specify a database name which is odd to me but maybe you're relying on the default database connection??
Do the following in Visual Studio.
- Go to SQL Server Object Explorer under the View menu.
- Add a SQL Server instance.
- Enter the database server name, database you're connecting to and the credentials to use. Also check the option to encrypt the data.
- Note that many SQL databases are using self-signed certs. If that is your case then you need to set Trust Server Certificate to true otherwise it will fail to connect. If you actually have a certificate that you managed then set it to false.
- Ensure you can connect successfully to the database.
- Open the properties of the database in Object Explorer window and find the
Connection String
property. - Copy the value and paste it into your code. Note that it'll add extra stuff around MARS and whatnot that you can remove if you like. The only fields that are generally needed are: server, database, User Id/Password or Integrated Security, Encrypt and Trust Server Certificate.