473,320 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

What is the format of a SQLConnection connection string?

xarzu
88 64KB
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;";
and

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
5 5242
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
AjayGohil
83 64KB
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
If you use ASP.net, 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
rwLinx
1 Bit
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;

Oracle:
> 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;

OLE DB:
> 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;

ODBC:
> 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.

> MySQL
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;

>SQLite
Driver={SQLite3 ODBC Driver};Database=F:\myDatabase.db;
Mar 30 '20 #5
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

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

Similar topics

3
by: syhart | last post by:
Please, anyone who has experience setting up a sql connection string in the web.config file, can you decipher this error.: Keyword not supported: 'datasource'. Description: An unhandled...
5
by: Fred Zuckerman | last post by:
Hello All, After reading in this group about the preference for connecting to a SQL Server using a connection string instead of a DSN file, I have done just that. BUT, I cannot update my data....
1
by: Matthew Wells | last post by:
What is the connection string linking an Access front end mdb to an Access back end mdb that has a database password set.using the standard linking process - no odbc or ado connections. Someone...
0
by: Gaurav | last post by:
Hi, I have a connection string "Data Source=db1.mynet;DATABASE=test;User ID=testuser;Password=test;" , when i use the connection string to get a dataset of all the tables of a database it...
7
by: Tee | last post by:
Hi, I need some help here for DSN connection string. I know it's not recommended to use DSN, even I dont like it as well ... but for now, my situation is I am using a shared hosting. I do not...
1
by: sal | last post by:
Greets, All Question with udl and connection string does it work? I'm having problems with the code below I keep getting an error "Keyword not supported 'File Name'" I was just following...
3
by: Pete Smith | last post by:
What is the connection string to connect MS Access database using OLEDB. Not able to write quickly the above connection string. Vb.Net and .Net Framework 1.1. Thank you, Pete
1
by: jesmi | last post by:
what is the connection string for coldfusion for connecting with ms access database? i need the connection string written in coldfusion. Thank you!! jesmi
3
by: Benedictum | last post by:
I have an Access database in remote server with a url of e.g. - http://www.myserver.com The database is located in a folder named "/data". What is the connection string be?
6
by: little83 | last post by:
Dear all i wrote one class to deal with sql database to insert and read data from that class only...and based on that one of the parmeters or the class is the sqlconnection SqlConnection...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.