Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
Connection string for connecting to data sources in vb

Connection string for connecting to data sources in vb

Ratings:

4.33

(3)
|Views: 7,022|Likes:
Published by Muneeb Khan
Different type of connection string for connecting vb.net to different data sources.
Different type of connection string for connecting vb.net to different data sources.

More info:

Published by: Muneeb Khan on Dec 02, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

02/01/2013

pdf

text

original

Connection string for connecting to data sources in VB.NET

A connection string is a string which is used to gain access to different data sources from a VB .Net or a C# .Net application. The data sources can be MS SQL Server, MS Access or SQL Server on remote server.

A connection string is made of many parts and one of them is the Provider. A provider allows us to specify the driver which can access the datasource in binary form. With the provider, we can setup a connection from an application and gain access to the datasource. In a connection string, we specify the appropriate provider depending on the datasource we wish to access. Note that when we need to connect to sql server we need not mention the provider in the connection string. You will see this, when we write the connection string for connecting a VB. Net application or C# application to an Sql Server database.

Connection string to connect to Sql Server database
VB 2005
Given below is the connection string for connecting a Visual Basic. Net application to an Sql Server
database.
Dim connectionString As String = \u201cData Source=SYS2;\u201d + \u201cintegrated security=SSPI;\u201d +
\u201cdatabase=FinAccounting\u201d
Given below is the connection string for connecting a C#. Net application to an Sql Server database.
string
connectionString
=
\u201cData
Source=SYS2;\u201d
+
\u201cintegrated
security=SSPI;\u201d
+
\u201cdatabase=FinAccounting\u201d;

In the above example, Data Source is the machine name of the computer that is running sql server, in this case SYS2. \u2018Integrated security\u2019 indicates that current user's windows credentials (username and password) are being used to access and connect to sql server. The possible values for Integrated Security

are
\u2018true\u2019,
\u2018yes\u2019,
and
\u2018sspi\u2019,
which
specify
a
secure
connection.

In the above code, "database" refers to the name of the specific database that we would like to access. A Connection string also has other properties like connection pooling, length of timeout period and security options. Note that we can use and implement a connection string without using these other properties. Connection string is a property of the connection object. While using the connection

string, we need to instantiate the Connection object. We will see how to do this in the coming topic.
Connection string to connect to a Microsoft access database
To connect to a Microsoft access database, use the following connection string.
Dim myConn As OleDbConnection = New OleDbConnection ()

MyConn.ConnectionString = \u201cProvider = Microsoft.Jet.OLEDB.4.0; Data \u201c & _
\u201cSource = C : \ data \ northwind.mdb ; User Id = guest; \u201c & _
\u201cPassword = isw3083\u201d

Observe that in the above connection string, we have specified a provider name in the connection
string.
We
need
to
do
this
when
we
use
a
OLEDB
.Net
data
provider.

Giving away username and password in the connection string code is vulnerable to phishing. An option to overcome this problem is by using the Windows integrated security. Consider the following connection

string.
string
connectionString
=
\u201cData
Source=SYS2;\u201d
+
\u201cintegrated
security=SSPI;\u201d
+
\u201cdatabase=FinAccounting\u201d;
By setting integrated security as SSPI, we are specifying that windows integrated security is the
security option chosen.
Connection string to connect to Sql Server database which is on a remote server
Below is an example of a connection string used to access a sql server database which is on the
remote
web
server
on
the
internet,
using
C#
code
in
an
.aspx
file.
string connectionString = "Data Source=201.73.323.39;database=FinAccounting;User
ID=sssabc123;Password=scss456;";

In the above code, we assign the IP address of the server to the \u2018Data Source\u2019, assign the name of the
database, assign the username and the password. The above code is used to connect to a database
hosted on a web server.

Let us see, what is a connection object, as the connection string is a property of the Connection
Object.
Connection Object

The Connection object establishes a connection to the database. Two of the most common Connection objects used are OleDbConnection and SqlConnection. Both the SqlConnection and OleDbConnection are namespaces and are inherited from the IdbConnection object. The commonly used property of the Connection object is the Connection string property.

ConnectionString property
This property is used to provide information, such as the data source and database name, that is used
to establish the connection with the database.
There are two ways of setting the Connection string property.
1. Using a parameterized Constructor
2. Using the default constructor

Activity (3)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->