|
-
Nov 21st, 2006, 02:07 AM
#1
Thread Starter
Member
[RESOLVED] change connection string at run-time
hi,
im new at this.. so excuse my ignorance. my application is connected to an sql server database (northwind) through a data environment. Is there a way I can change my connection string at run-time?
for ex. I have a comboBox containing databse names " northwind, pubs, dbo ... " when i choose one at run time , i want the connection string to change to that database.. I hope thats clear enough. thanks in advance.
-
Nov 21st, 2006, 02:31 AM
#2
Re: change connection string at run-time
Welcome to VBF !
you can very well do it by closing and opening the connection at any point of time...
if you post your existing connection string then we can give you the code...
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Nov 21st, 2006, 02:43 AM
#3
Thread Starter
Member
Re: change connection string at run-time
Provider=MSDASQL.1;Persist Security Info=False;Data Source=Northwind;Initial Catalog=Form Designer
-
Nov 21st, 2006, 03:17 AM
#4
Re: change connection string at run-time
VB Code:
'Mark Refernce to Microsoft ADO 2.x Library from the Project Meu
Option Explicit
Private Sub CmdConnect_Click()
Dim db As New ADODB.Connection 'for making connection
Dim rs As New ADODB.Recordset 'for opening the record set
Dim sconnectionstring As String 'for connction string
sconnectionstring = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Northwind;Initial Catalog=Form Designer"
db.Open sconnectionstring 'open the connection
If db.State = 1 Then
MsgBox "Connection succesfull"
Else
MsgBox "Connction Failed"
End If
End Sub
Please mark you thread resolved using the Thread Tools as shown
-
Nov 21st, 2006, 04:11 AM
#5
Hyperactive Member
Re: change connection string at run-time
If you want to change database at runtime (select from a combo box) you must change the following line in danasegarane's code
 Originally Posted by danasegarane
VB Code:
sconnectionstring = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Northwind;Initial Catalog=Form Designer"
As
VB Code:
dim sCatalog as string
sCatalog = combo1.text
sconnectionstring="Provider=MSDASQL.1;Persist Security Info=False;Data Source=Northwind;"
sconnectionstring= sconnectionstring & "Initial Catalog= " & sCatalog & ""
-
Nov 21st, 2006, 05:00 AM
#6
Thread Starter
Member
Re: change connection string at run-time
thanx much.. problem solved
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|