943,973 Members | Top Members by Rank

Ad:
May 21st, 2007
0

Connection String

Expand Post »
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!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
pbrookee is offline Offline
34 posts
since Apr 2007
May 21st, 2007
0

Re: Connection String

you could put up a dialog box asking user to open database they wish to open.
Reputation Points: 22
Solved Threads: 19
Posting Whiz
DenisOxon is offline Offline
345 posts
since Jan 2007
Jun 2nd, 2007
0

Re: Connection String

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
Reputation Points: 10
Solved Threads: 9
Junior Poster
AV Manoharan is offline Offline
166 posts
since Jun 2007
Jun 3rd, 2007
0

Re: Connection String

check this out :-

conn.ConnectionString = app.path & "\CheckInfo.mdb"

make sure the .mdb file does exist in the same folder as ur project files.
Reputation Points: 30
Solved Threads: 49
Posting Pro
choudhuryshouvi is offline Offline
553 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help: Global Hotkey
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Can anyone help me, please?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC