473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

adodb connection string question

Hey guys,

I've got a database which I am linking into a form on VB6. The form has only an ADODB function and a Datagrid to display the records.
I currently have this working fine where I build the connection string and then specify where the database is located.

However I am wondering if there is anyway to set the connection string used as the database within the folder where the VB project is contained, using the
chdir (app.path) function perhaps?

Each time I run my program on another computer I have to reprogram the database path which is quite annoying, any ideas on how to solve this?

Many thanks,
Stephen
Feb 23 '12 #1
3 1842
MikeTheBike
639 Expert 512MB
Hi

On the basis that the DB is on you (company?) network then I personaly use udl file(s) to hold my connectuon strings located on the network (although you can put in the directory where your code is running and use this in the udl file path in you program.

The avantage of this is that if the DB is move or renamed you just point the uld file at the new file/location without any need to recode your program(s) (I have many spreadsheets that create variouse reports/graphs from multiple databases. It is much easier in Excel!!)

There is an excelent article on uld files in this forum here http://bytes.com/topic/access/insigh...data-link-file

HTH


MTB
Feb 24 '12 #2
my suggestion is try to create a configuration file(external file) wherein the connection string is handled

here is the step:

create first a config file to put your connection string named "config.ini":
=======
Driver=MySQL ODBC 3.51 Driver;
Database=dbfile;
UID=root;
PWD=;
=======

write a code in a module:
======
Public cn as New ADODB.Connection
Public FileLocation As String
Public config_string As String
Public FileNum


Public Sub Connection()
On Error GoTo Disconnect
FileLocation = App.Path & "\Config\config.ini"
FileNum = FreeFile
Open FileLocation For Input As #FileNum
Do Until EOF(FileNum) = True
Line Input #FileNum, Data
config_string = config_string + Data
Loop
Close #FileNum

cn.CursorLocation = adUseClient
If cn.State = 1 Then cn.Close
cn.Open config_string
Exit Sub
Disconnect:
MsgBox Err.Description, vbCritical, Err.Number
MsgBox "System has been Terminated!", vbExclamation
End
End Sub
======

Private Sub Form_Load()
Call Connection
End Sub
Feb 25 '12 #3
'create an .exe format of your project
'put your .exe project in the folder where your database can be found.

'set the Data Source in your Connection String

Data Source="& app.Path &"/YourDatabaseName.mdb;

'PS: you can also specify subfolders
'for example your database can be found on the subfolder named "System_data"

'your DataSource look like this..

Data Source="& app.Path &"/System_data/YourDatabase.mdb;

"make sure there is no spacing between "& and &" because ""&eee&"e" = eeee
""&eee& "e" = eee e
Mar 17 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Dave | last post by:
I have two sites: www.site_A.com & www.site_A_news.com Site_A is in d:\webs\site_a & uses an Access DB in d:\webs\site_a\data\db.mdb Site_A_news is in d:\webs\site_a\site_a_news also...
3
by: Tim Marshall | last post by:
I'm starting to work with connection strings and Oracle. The connection string syntax is pretty much the same as MS SQL (based on one of Lyle's posts in response to a question I had about a jmonth...
1
by: Nigel C | last post by:
Access 2000 - A am trying to access another Access 2000 database from a code module. I have seen examples of the ADODB connection string - to connect to an access database however the database...
2
by: Jason Huang | last post by:
Hi, Will it make it any difference if I replace the 'data source' in the "data source=MyServer;uid=SA;password=MyPwd;database=MyDB" with IP, e.g.,192.168.1.1? Where MyServer's IP is...
6
by: Sisnaz | last post by:
In classic ASP I could specify a relative path (server side mapping) or absolute path to an Access database file. I can connect to an access file with no problems using the absolute path of...
4
by: William | last post by:
I am using SQL MSDE edition due to financial reasons (it's free). I have a question regarding connection strings. Almost every publication, online example or website uses some version of the...
2
by: gary g. | last post by:
I was wondering if it was possible to store a connection string only once in a single config file, and let it be accessible to every project in the solution (web included). This way if the...
2
LoanB
by: LoanB | last post by:
Hi Guys I have th efollowing connection String: conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ADDRESS.ACCDB;Persist Security Info=False"; This allows the application...
2
LoanB
by: LoanB | last post by:
Hi I have the following code: string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); This returns the path from which the...
5
by: Onetoomany | last post by:
Hi, I've just upgraded to Small Business Server 2008, 64 bit. My website, which worked perfectly before, is having issues with the connection string: I've tried: 1) sConnection =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.