Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the connection string? Give some examples?

user-image
Question added by Deleted user
Date Posted: 2014/08/09
Deva Gnanam Jayaseelan
by Deva Gnanam Jayaseelan , Lead SSE , MS

When your application connects to a database(db) or a data file you let your provider (ADO/ADO.Net) utilize to do the job for you. This connection string contains the info that the provider need to know to be able to establish a connection to the related db or datafile.

 

You can see this C#.Net  example which creates a SQLConnection and set the ConnectionString property before opening the connection:

 

private static void OpenSqlConnection() { string connectionString = GetConnectionString(); using (SqlConnection connection = new SqlConnection()) { connection.ConnectionString = connectionString; connection.Open(); Console.WriteLine("State: {0}", connection.State); Console.WriteLine("ConnectionString: {0}", connection.ConnectionString); } } static private string GetConnectionString() { // To avoid storing the connection string in your code,   // you can retrieve it from a configuration file.  return "Data Source=MSSQL1;Initial Catalog=AdventureWorks;" + "Integrated Security=true;"; }

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

 

Below example is using PHP:

 

$link mysql_connect('localhost''mysql_user''mysql_password');if (!$link) {    die('Could not connect: ' mysql_error());}echo 'Connected successfully';mysql_close($link);

Junaid Saleem
by Junaid Saleem , System Analyst , Knight Group

Connection String is simply a string that use to connect any type of Database to perform operaation on it. In any Language.

For Example: 

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

User ID=myDomain\\myUsername;Password=myPassword;

Abdul Khader Shaik
by Abdul Khader Shaik , IT & Ops Manager , TheSmartlabs

A connection string is a string that specifies information about a data source and the means of connecting to it. It is passed in code to an underlying driver or provider in order to initiate the connection.

 

Example

[SettingsBindableAttribute(true)]

public:

virtual property String^ ConnectionString {

String^ get () override;

void set (String^ value) override;

}

 

 

Exceptions:

ArgumentException -An invalid connection string argument has been supplied, or a required connection string argument has not been supplied.

 

 

For further refer these

 

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

 

 

 

Other Example in .NET

 

When your application connects to a database or a data file you let ADO or ADO.Net utilize a provider to do the job for you. The connection string contains the information that the provider need to know to be able to establish a connection to the database or the data file.

 

Reqrments

1.A connection string consists of a series of keyword - value pairs separated by semicolons (;)

2.The equal sign (=) connects each keyword and its value

Example: Key1=Value1;Key2=Value2;Key3=Value3;

 

Umair Aslam
by Umair Aslam , Senior Software Engineer , Ithaka

Connection string is the sequence of characters that are used to connect to a database for example jdbc connection string for mysql database would look like 'jdbc:mysql://HOST/DATABASE com.mysql.jdbc.Driver'. HOST will be replaced by address of host machinne and DATABASE will be replaced by database name.

Muktar SayedSaleh
by Muktar SayedSaleh , Software Engineering Manager , AIRASIA

it is a string with special format contains credentials and other necessary information to create a connection with some resource.it is usually used with databases connection especially with oop programming languages.

Samir Alkhatib
by Samir Alkhatib , IT Support Engineer , Vianeos

Connection string  is a user credentials to accress some sort of data (Database, website private pages...etc), it's called connection string because mostly it's passed to the server by one line of code.

 

والله اعلم اخي عبد الرحمن 

More Questions Like This