Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connection string

Status
Not open for further replies.

gustaf111

Programmer
Jan 16, 2011
87
SE
Hello,

Public Const ConnectionString = "DRIVER=SQL Server;UID=rfd;PWD=password;SERVER=ETE0349\SQLEXPRESS;APP=RFD;DATABASE=RFD"

I have this connection string: DRIVER: Will that always be SQL could it be something else ?

APP: Is that alwas the table name ?
DATABASE: Is that Always the table name and always the same as APP

Cheers
Gustaf
 
UID = User Identification ?
PWD = Password ?
APP = ?
 
APP: Is that alwas the database name ?

DATABASE: Is that Always the database name and always the same as APP
 
Thanks.

The DRIVER will that always be "SQL Server" for an MS SQL Server Express database ?

APP, DATABASE will they always be the same ? Do I need both of them ?
 
Personally, I wouldn't use driver. I would use provider instead. If I am not mistaken, using DRIVER will cause the application to use ODBC to connect to the database. ODBC is just another layer of software that you don't actually need. So I would do something like this:

Code:
Provider=SQLNCLI10;Server=SERVER-Name\SQLExpress;Database=DataBaseName;Uid=Username; Pwd=Password;

The Provider part can be a little tricky because it depends on what is installed on the client computer.

SQLNCLI10 = SQL Server 2008 native client driver.
SQLNCLI = SQL Server 2005 native client driver
SQLOLEDB = SQL Server 2000 OLEDB provider

SQLOLEDB has been included with operating systems for a very long time, so you can be reasonably certain that it will exist.

The native client drivers are free to download from Microsoft.

Scroll down to "Microsoft SQL Server 2008 Native Client"

Using the native client drivers will be slightly faster. If you are packaging your application for distribution, you'll probably want to include the native client drivers along with your install.


UID = User Identification ?
This is the SQL Server login name. When you use UID, you are essentially saying, "I want to use SQL Authentication". Be default, SQL Authentication is not enabled.

PWD = Password ?
Yes.

APP = ?
This would represent the name of the application that is connecting to SQL Server. You do not need to use APP (I never do). If you do use APP, the name of your application will show up when you run certain queries (like sp_who2).

APP, DATABASE will they always be the same ? Do I need both of them ?

Technically, you don't need either of them. Each login has a default database. By default, the default database is Master, and not your user database. If you do NOT specify database, you will be connected to the login's default database (probably master) instead of the user database that you actually want. I never use APP, but I always use DATABASE.

There's nothing wrong with using APP in your connection string, in fact, I should probably start doing this myself. The APP doesn't have to be the same as the database name. It can be the same, but doesn't have to be. Just like the street you live on could be the same as your last name, but doesn't have to be.

In my app, it is common for my customers to do a yearly process that effectively creates a new database. This allows them to connect to "last year's" database to run reports. So, I could use APP=Widget; DATABASE=Widget2011 and then next year... APP=Widget; DATABASE=Widget2012;

Make sense?

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top