By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
463,030 Members | 517 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 463,030 IT Pros & Developers. It's quick & easy.

What is the format of a SQLConnection connection string?

P: 68
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:

Expand|Select|Wrap|Line Numbers
  1.  "Data Source=(local);Initial Catalog=AdventureWorks; Integrated Security=SSPI;";

Expand|Select|Wrap|Line Numbers
  1.  "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?
Jul 9 '18 #1
Share this Question
Share on Google+
5 Replies

P: 10
If you want to connect local Database then use below code.
Data Source='server name';Initial Catalog='your db name';Integrated Security=True
Dec 11 '18 #2

P: 66
format of SQL connection string
Expand|Select|Wrap|Line Numbers
  1. <add name="name" connectionString="Data Source='Server Name';Initial Catalog='Database name';Integrated Security=true;UID='Id';PWD='password';" providerName="providername"/>
Dec 13 '19 #3

P: 4
If you use, you can use this example connection string in the "Web.config" file:
Expand|Select|Wrap|Line Numbers
  1. <add name = "YouDbContext"
  2.    connectionString = "Data Source = (LocalDb) \ MSSQLLocalDB; Initial Catalog = NameDb; Integrated Security = SSPI;"
  3.    providerName = "System.Data.SqlClient"
  4. />
Mar 27 '20 #4

P: 1
Connection string properties vary depending on the type of database driver used.

Here are a few examples showing the variations:

SQL Server:
> Not named, Windows authentication: Data Source=serverAddress;Initial Catalog=databaseName;Integrated Security=True;

> Named server, no Windows authentication: [i]Data Source=serverName\instanceName;Initial Catalog=databaseName;Integrated Security=;User ID=username;Password=password;

> Using TNS-names entry: Data Source=TNSname;User ID=username;Password=password;

> Without using TNS-names entry: Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=s erverAddress)(PORT=port))(CONNECT_DATA=(SERVER=DED ICATED)(SERVICE_NAME=serviceName));User ID=username;Password=password;

> Windows Authentication: Provider=sqloledb;Data Source=serverAddress;Initial Catalog=databaseName;Integrated Security=SSPI;

> No Windows authentication: Provider=sqloledb;Data Source=serverAddress;Initial Catalog=databaseName;Integrated Security=;User ID=username;Password=password;

> Microsoft Access database: Driver={Microsoft Access Driver (*.mdb)};DBQ=databaseFilePath;

> System Data Source Name, Windows authentication:DSN=dataSourceName;Trusted_Connection=Yes;

>System Data Source Name, no Windows authentication: DSN=dataSourceName;Uid=username;Pwd=password;

Examples of connections to databases on cloud servers:
Note: The DSN property is not used when connecting to a database on a cloud server.

Uid=root;Pwd= password;Driver={MySQL ODBC 8.0 ANSI Driver};Server=localhost;Database=myDatabase;

> PostgreSQL
Uid=postgres;Pwd=password;Driver={PostgreSQL ANSI(x64)};Server=localhost;Database=myDatabase;

Driver={SQLite3 ODBC Driver};Database=F:\myDatabase.db;
Mar 30 '20 #5

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

The catalog is a different name for the 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];"
Apr 3 '20 #6

Post your reply

Sign in to post your reply or Sign up for a free account.