0

What is the format of a SqlConnection connection string that is passed in the constructor method? I have run a search engine search online and all I could find so far is examples like:

"Data Source=(local);Initial Catalog=AdventureWorks; Integrated Security=SSPI;"

"User Id=sa;Server=localhost;Initial Catalog=Test;"

The examples raises questions. Since the SQL Server Management Studio (SSMS) program offers a different set of fields during start up in order to connect to a database, I have to ask how does "Server type, "Server name", "Authentication", "User name" and "Password". Also, is "Catalog" another name for a database table?

2
  • Data Source = Server, Initial Catalog = Database (you don't provide this in SSMS), Integrated Security = SSPI = Authentication = Windows credentials Commented Jul 6, 2018 at 22:05
  • 6
    My favorite site for connection strings: connectionstrings.com . You should be able to figure out the meanings of the fields by deducting from the massive amount of variation examples they provide. Commented Jul 6, 2018 at 22:09

2 Answers 2

4

You should be more specific about what your goal is. This will provide you with better answers.

Catalog is a different name for database, you're connecting to a SQL server and use catalog to specify the database which you want to access.

Server type is either SQL or Windows Authentication

If you're trying to generate a ConnectionString in a string format but don't know how to format the string. The best way is to use the SqlConnectionStringBuilder . After you've set all the variables in the builder use the toString() method to convert it to a string. That way you don't have to worry about how to format your connectionstring.

If you have the string already, or don't need to generate it on the fly you can put it in your web/app.config and use it directly.

A very basic connectionstring that uses SQL authentication looks like this:

"data source=[sqlserver];initial catalog=[database];user id=[username];password=[password];"
Sign up to request clarification or add additional context in comments.

Comments

3

I always look at this website for connection string patterns and examples: https://www.connectionstrings.com/sql-server/

Comments

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.