Connection String

Reply

Join Date: Apr 2007
Posts: 34
Reputation: pbrookee is an unknown quantity at this point 
Solved Threads: 0
pbrookee pbrookee is offline Offline
Light Poster

Connection String

 
0
  #1
May 21st, 2007
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!!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 319
Reputation: DenisOxon is an unknown quantity at this point 
Solved Threads: 15
DenisOxon's Avatar
DenisOxon DenisOxon is offline Offline
Posting Whiz

Re: Connection String

 
0
  #2
May 21st, 2007
you could put up a dialog box asking user to open database they wish to open.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 166
Reputation: AV Manoharan is an unknown quantity at this point 
Solved Threads: 9
AV Manoharan AV Manoharan is offline Offline
Junior Poster

Re: Connection String

 
0
  #3
Jun 2nd, 2007
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
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 537
Reputation: choudhuryshouvi is an unknown quantity at this point 
Solved Threads: 49
choudhuryshouvi's Avatar
choudhuryshouvi choudhuryshouvi is offline Offline
Posting Pro

Re: Connection String

 
0
  #4
Jun 3rd, 2007
check this out :-

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

make sure the .mdb file does exist in the same folder as ur project files.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC