Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old November 24th, 2005, 09:35 PM
baseballdude_'s Avatar
baseballdude_ baseballdude_ is offline
Expert Learner
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2005
Location: Wisconsin
Posts: 1,877 baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 22104 Folding Title: Starter FolderFolding Points: 22104 Folding Title: Starter Folder
Time spent in forums: 1 Week 5 Days 11 h 49 m 2 sec
Reputation Power: 62
Send a message via AIM to baseballdude_ Send a message via MSN to baseballdude_ Send a message via Yahoo to baseballdude_ Send a message via Google Talk to baseballdude_
Connection String Function

Here's a shortcut function I created for three common databases. You can add to it or modify it to your needs.

The correct syntax would be:
Code:
Conn.Open = SQLConnect("Type of Database (1, 2, or 3)", "Localhost, Server, or DB Path", "Database Name", "User ID for database", "Password for database")

ASP Code:
Original - ASP Code
  1. Function SQLConnect(intType, strServer, strDB, strUid, strPwd)
  2.     If intType = 1 Then
  3.         'MySQL Database
  4.         SQLConnect = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & strServer & ";DATABASE=" & strDB & ";UID=" & strUid & ";PWD=" & strPwd & ";OPTION=3;"
  5.     ElseIf intType = 2 Then
  6.         'Microsoft Access Database
  7.         SQLConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & strServer & ";UID=" & strUid & ";PWD=" & strPwd & ";"
  8.     Else
  9.         'Microsoft SQL Server Database
  10.         SQLConnect = "DRIVER={SQL Server};SERVER=" & strServer & ";DATABASE=" & strDB & ";UID=" & strUid & ";PWD=" & strPwd & ";"
  11.     End If
  12. End Function

Reply With Quote
  #2  
Old November 27th, 2005, 10:38 PM
baseballdude_'s Avatar
baseballdude_ baseballdude_ is offline
Expert Learner
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2005
Location: Wisconsin
Posts: 1,877 baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)baseballdude_ User rank is Second Lieutenant (5000 - 10000 Reputation Level)  Folding Points: 22104 Folding Title: Starter FolderFolding Points: 22104 Folding Title: Starter Folder
Time spent in forums: 1 Week 5 Days 11 h 49 m 2 sec
Reputation Power: 62
Send a message via AIM to baseballdude_ Send a message via MSN to baseballdude_ Send a message via Yahoo to baseballdude_ Send a message via Google Talk to baseballdude_
And if you're really lazy, I've created it with one string, seperated my commas which are split into an array and used (I'm lazy)
Code:
Example
SQLConnect("1,localhost,My_Database,Username,Password")

Code:
Function
Function SQLConnect(arrX)
	arrX = Split(arrX,",")

	If arrX(0) = 1 Then
		SQLConnect = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & arrX(1) & ";DATABASE=" & arrX(2) & ";UID=" & arrX(3) & ";PWD=" & arrX(4) & ";OPTION=3;"
	ElseIf intType = 2 Then
		SQLConnect = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & arrX(1) & ";UID=" & arrX(3) & ";PWD=" & arrX(4) & ";"
	Else
		SQLConnect = "DRIVER={SQL Server};SERVER=" & arrX(1) & ";DATABASE=" & arrX(2) & ";UID=" & arrX(3) & ";PWD=" & arrX(4) & ";"
	End If
End Function

Reply With Quote
  #3  
Old November 28th, 2005, 03:54 AM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,936 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1Folding Points: 340465 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 11 h 28 m
Reputation Power: 1537
lol nice trick!

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Connection String Function


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway