| | |
Connection String
![]() |
•
•
Join Date: Apr 2007
Posts: 34
Reputation:
Solved Threads: 0
Hello all!

I am creating a program which reads data from a database. How can I change the connection string to format anyone who would use this program on there computer?
My current connection string is made to specifically read from my folder(s)...
conn.ConnectionString = "C:\Documents and Settings\servername.\Desktop\Pamela\CheckReader\Database\CheckInfo.mdb"
Thanks much!
Kudos!!

I am creating a program which reads data from a database. How can I change the connection string to format anyone who would use this program on there computer?
My current connection string is made to specifically read from my folder(s)...
conn.ConnectionString = "C:\Documents and Settings\servername.\Desktop\Pamela\CheckReader\Database\CheckInfo.mdb"
Thanks much!
Kudos!!
•
•
Join Date: Jun 2007
Posts: 166
Reputation:
Solved Threads: 9
First create a file (say myfile.txt) in C drive of each computer where your program access the dataBase with the following lines of information in quotes.
DataSource = "ComputerName"
DBUser = "UserName"
DBPassword = "Password"
Catalog = "Databasname"
Provider = "SQLOLEDB.1"
In your VB project file under
Private Sub Form_load()
'Open this File myfile.txt and read each line and store the values in 'variables such as
Dim string_datasorce,string_dbuser,string_password,string_catalog,string_provider,LineRead as String
'Two Loop Indexes i and j
Dim i, j as integer
Open "c:\myfile.txt" For Input As #1
'Put it in a loop to read each characters of the values in quotes
Do While Not EOF(1)
Line Input #1, LineRead
If Mid(LineRead,1,10) = "DataSource" then
'read the consecutive characters up to the last quote say upto 100 'characters
For i = 11 to 100
if Mid(LineRead, i,1) = Char(34) then
For j = i + 1 to 100
if Mid(LineRead, j, 1) = Char(34) then
string_datasource = Mid(LineRead, i + 1, j - 1 - i)
Exit For
End If
Next j
Endif
Next i
Else
' Now the next line containing DBUser
If Mid(LineRead, 1,6) = "DBUser" then
'Same two loops as before indexing i and j
For i = 8 to 100
' ...............
' string_dbuser = Mid(LineRead ...........)
'.............
' Inside the do loop read in to all string Variables the data as I have 'shown it in the first variable
Loop
Close #1
'Now you are ready with the data in the corresponding variables
'Now Comes the connection string and recordset. You Can Place 'them as Global Variable
Dim MyConnectionString As New ADODB.Connection
Dim MyCursor as New ADODB.Recordset
' In your program where you want to access the database simply 'place the following codes
MyConnectionString.ConnectionString = "Provider = string_provider;UID = string_dbuse;PWD = string_password;Data Source = string_datasource;Initial Catalog=string_catalog
MyConnectionString.Open
MyCursor.ActiveConnection = MyConnectionString
Ctype = adOpenStatic
CLocation = adUseServer
MyCursor.CursorLocation = CLocation
MyCursor.CursorType = Ctype
If MyCursor.State = adStateOpen then
MyCursor.Close
End If
MyCursor.Open "SELECT * FROM MYTABLE............
If MyCursor.State = adStateOpen then
MyCursor.Close
End If
'That's all
'HAPPY PROGRAMING
DataSource = "ComputerName"
DBUser = "UserName"
DBPassword = "Password"
Catalog = "Databasname"
Provider = "SQLOLEDB.1"
In your VB project file under
Private Sub Form_load()
'Open this File myfile.txt and read each line and store the values in 'variables such as
Dim string_datasorce,string_dbuser,string_password,string_catalog,string_provider,LineRead as String
'Two Loop Indexes i and j
Dim i, j as integer
Open "c:\myfile.txt" For Input As #1
'Put it in a loop to read each characters of the values in quotes
Do While Not EOF(1)
Line Input #1, LineRead
If Mid(LineRead,1,10) = "DataSource" then
'read the consecutive characters up to the last quote say upto 100 'characters
For i = 11 to 100
if Mid(LineRead, i,1) = Char(34) then
For j = i + 1 to 100
if Mid(LineRead, j, 1) = Char(34) then
string_datasource = Mid(LineRead, i + 1, j - 1 - i)
Exit For
End If
Next j
Endif
Next i
Else
' Now the next line containing DBUser
If Mid(LineRead, 1,6) = "DBUser" then
'Same two loops as before indexing i and j
For i = 8 to 100
' ...............
' string_dbuser = Mid(LineRead ...........)
'.............
' Inside the do loop read in to all string Variables the data as I have 'shown it in the first variable
Loop
Close #1
'Now you are ready with the data in the corresponding variables
'Now Comes the connection string and recordset. You Can Place 'them as Global Variable
Dim MyConnectionString As New ADODB.Connection
Dim MyCursor as New ADODB.Recordset
' In your program where you want to access the database simply 'place the following codes
MyConnectionString.ConnectionString = "Provider = string_provider;UID = string_dbuse;PWD = string_password;Data Source = string_datasource;Initial Catalog=string_catalog
MyConnectionString.Open
MyCursor.ActiveConnection = MyConnectionString
Ctype = adOpenStatic
CLocation = adUseServer
MyCursor.CursorLocation = CLocation
MyCursor.CursorType = Ctype
If MyCursor.State = adStateOpen then
MyCursor.Close
End If
MyCursor.Open "SELECT * FROM MYTABLE............
If MyCursor.State = adStateOpen then
MyCursor.Close
End If
'That's all
'HAPPY PROGRAMING
![]() |
Similar Threads
- connection string of SqlConnection (C#)
- Connection String (MS Access and FileMaker Pro)
- connection string (ASP.NET)
- Dynamic Connection String Using ADO (Visual Basic 4 / 5 / 6)
- SQL not a trusted connection?! (ASP.NET)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Help: Global Hotkey
- Next Thread: Can anyone help me, please?
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





