473,385 Members | 1,769 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,385 software developers and data experts.

Access DB Path

How can I customize, at runtime, the path for the OLEDB connection uses. I
used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.

Jul 29 '07 #1
7 2183
Normally when you use the designer you use the Special data directory to
store your database ( it then becomes dynamic as the app will always look
to the data directory regardless where it is installed )
you can recognize this by the |Data Directory| in your connection string, it
means that you chose to copy the mdb file into your project when you use the
designer to generate the connection strings.

If you want to modify it, please do not change it in the setting tab of
project property.You can achieve that by "Right Click" your table adapter,
choose "Configure", and with two clicks of previous, you can change the
connection string.

Another option would be to concenate your own connection string , and do
everything from code ( loose the wizards )

regards

Michel



"Tony K" wrote:
How can I customize, at runtime, the path for the OLEDB connection uses. I
used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.
Jul 30 '07 #2
Thank you Michel. I'm too far into my project to re-write that much code
(9 different forms that use that connection string). I'll have to get the
path from my customer and just recompile with that path for the connection
string and make sure the Access DB is in that path before they use the app.

Thank you again,

Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:AF**********************************@microsof t.com...
Normally when you use the designer you use the Special data directory to
store your database ( it then becomes dynamic as the app will always
look
to the data directory regardless where it is installed )
you can recognize this by the |Data Directory| in your connection string,
it
means that you chose to copy the mdb file into your project when you use
the
designer to generate the connection strings.

If you want to modify it, please do not change it in the setting tab of
project property.You can achieve that by "Right Click" your table adapter,
choose "Configure", and with two clicks of previous, you can change the
connection string.

Another option would be to concenate your own connection string , and do
everything from code ( loose the wizards )

regards

Michel



"Tony K" wrote:
>How can I customize, at runtime, the path for the OLEDB connection uses.
I
used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.
Jul 30 '07 #3


i had just some spare time to dig some deeper
so this should then be your solution

'set a reference to system.configuaration
'set the following imports stratement above your class
'Imports System.Configuration

' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
'the full connection string name. normally designer generated is
assemblyname
'.My.MySettings.connectionName
'below is a sample how i used it with my test app
Dim csName As String = "TestRptWO.My.MySettings.DbCon"
' Create a connection string element
'( connection string how you want it i tested it with sql server but
it should work for anny provider )
Dim csSettings _
As New ConnectionStringSettings( _
csName, _
"LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" + _
"Initial Catalog=aspnetdb", "System.Data.SqlClient")

' Get the connection strings section.
Dim csSection _
As ConnectionStringsSection = _
config.ConnectionStrings

'first remove the old section from the collection
csSection.ConnectionStrings.Remove(csName)
' Add the new element.
csSection.ConnectionStrings.Add(csSettings)

' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
with the above code you can change , remove or add connection strings
generated by the designer or even add your own custom ones through code

regards

Michel Posseth

"Tony K" wrote:
Thank you Michel. I'm too far into my project to re-write that much code
(9 different forms that use that connection string). I'll have to get the
path from my customer and just recompile with that path for the connection
string and make sure the Access DB is in that path before they use the app.

Thank you again,

Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:AF**********************************@microsof t.com...
Normally when you use the designer you use the Special data directory to
store your database ( it then becomes dynamic as the app will always
look
to the data directory regardless where it is installed )
you can recognize this by the |Data Directory| in your connection string,
it
means that you chose to copy the mdb file into your project when you use
the
designer to generate the connection strings.

If you want to modify it, please do not change it in the setting tab of
project property.You can achieve that by "Right Click" your table adapter,
choose "Configure", and with two clicks of previous, you can change the
connection string.

Another option would be to concenate your own connection string , and do
everything from code ( loose the wizards )

regards

Michel



"Tony K" wrote:
How can I customize, at runtime, the path for the OLEDB connection uses.
I
used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.
Jul 31 '07 #4

"Tony K" <no************@kingprogramming.comwrote in message
news:A5**********************************@microsof t.com...
How can I customize, at runtime, the path for the OLEDB connection uses.
I used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.
The Database property of the OleDBConnection object is readonly, but you can
change the ConnectionString which contains the database filename:

MyTableAdapter.Connection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyDatabaseFilename

Put this in your form_load event before the database is opened.

There is also a ChangeDatabase method which looks promising, but for some
bizarre reason this only works after the database has been opened.
Jul 31 '07 #5
Thanks again. I will try this when I get home today.
Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:48**********************************@microsof t.com...
>

i had just some spare time to dig some deeper
so this should then be your solution

'set a reference to system.configuaration
'set the following imports stratement above your class
'Imports System.Configuration

' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
'the full connection string name. normally designer generated is
assemblyname
'.My.MySettings.connectionName
'below is a sample how i used it with my test app
Dim csName As String = "TestRptWO.My.MySettings.DbCon"
' Create a connection string element
'( connection string how you want it i tested it with sql server
but
it should work for anny provider )
Dim csSettings _
As New ConnectionStringSettings( _
csName, _
"LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" +
_
"Initial Catalog=aspnetdb", "System.Data.SqlClient")

' Get the connection strings section.
Dim csSection _
As ConnectionStringsSection = _
config.ConnectionStrings

'first remove the old section from the collection
csSection.ConnectionStrings.Remove(csName)
' Add the new element.
csSection.ConnectionStrings.Add(csSettings)

' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
with the above code you can change , remove or add connection strings
generated by the designer or even add your own custom ones through code

regards

Michel Posseth

"Tony K" wrote:
>Thank you Michel. I'm too far into my project to re-write that much code
(9 different forms that use that connection string). I'll have to get
the
path from my customer and just recompile with that path for the
connection
string and make sure the Access DB is in that path before they use the
app.

Thank you again,

Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote
in
message news:AF**********************************@microsof t.com...
Normally when you use the designer you use the Special data directory
to
store your database ( it then becomes dynamic as the app will always
look
to the data directory regardless where it is installed )
you can recognize this by the |Data Directory| in your connection
string,
it
means that you chose to copy the mdb file into your project when you
use
the
designer to generate the connection strings.

If you want to modify it, please do not change it in the setting tab of
project property.You can achieve that by "Right Click" your table
adapter,
choose "Configure", and with two clicks of previous, you can change the
connection string.

Another option would be to concenate your own connection string , and
do
everything from code ( loose the wizards )

regards

Michel



"Tony K" wrote:

How can I customize, at runtime, the path for the OLEDB connection
uses.
I
used the Add Data Source Wizard and found the path set by the wizard
is
ReadOnly.
Jul 31 '07 #6
Phil,
Thank you for the info. I now have a couple things to try later today.

Tony K
"Phil" <N/Awrote in message
news:46**********************@ptn-nntp-reader02.plus.net...
>
"Tony K" <no************@kingprogramming.comwrote in message
news:A5**********************************@microsof t.com...
>How can I customize, at runtime, the path for the OLEDB connection uses.
I used the Add Data Source Wizard and found the path set by the wizard is
ReadOnly.

The Database property of the OleDBConnection object is readonly, but you
can change the ConnectionString which contains the database filename:

MyTableAdapter.Connection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyDatabaseFilename

Put this in your form_load event before the database is opened.

There is also a ChangeDatabase method which looks promising, but for some
bizarre reason this only works after the database has been opened.
Jul 31 '07 #7
Michel,
Thank you very much. That was cool of you to spend the time digging for
my problem. It worked perfectly with my Access DB and also using the
OpenFileDialog to search for the file.

I'll post my code here:
This was inside the button_click event.

Dim config As System.Configuration.Configuration =
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
Dim csName As String =
"Inventory.My.MySettings.Inventory_management_data baseConnectionString"

'Search for filepath to *.mdb Access file
Dim path As String
OpenFileDialog1.ShowDialog()
path = Me.OpenFileDialog1.FileName
Me.DBPathTextBox.Text = path

'Create a connection string element
Dim csSettings As New ConnectionStringSettings(csName,
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.DBPathTextBox.Text)

'Get the connection strings section
Dim csSection As ConnectionStringsSection = config.ConnectionStrings

'first remove the old section from the collection
csSection.ConnectionStrings.Remove(csName)

'Add the new element
csSection.ConnectionStrings.Add(csSettings)

'Save the configuration file
config.Save()

Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote in
message news:48**********************************@microsof t.com...
>

i had just some spare time to dig some deeper
so this should then be your solution

'set a reference to system.configuaration
'set the following imports stratement above your class
'Imports System.Configuration

' Get the application configuration file.
Dim config _
As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
'the full connection string name. normally designer generated is
assemblyname
'.My.MySettings.connectionName
'below is a sample how i used it with my test app
Dim csName As String = "TestRptWO.My.MySettings.DbCon"
' Create a connection string element
'( connection string how you want it i tested it with sql server
but
it should work for anny provider )
Dim csSettings _
As New ConnectionStringSettings( _
csName, _
"LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI;" +
_
"Initial Catalog=aspnetdb", "System.Data.SqlClient")

' Get the connection strings section.
Dim csSection _
As ConnectionStringsSection = _
config.ConnectionStrings

'first remove the old section from the collection
csSection.ConnectionStrings.Remove(csName)
' Add the new element.
csSection.ConnectionStrings.Add(csSettings)

' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
with the above code you can change , remove or add connection strings
generated by the designer or even add your own custom ones through code

regards

Michel Posseth

"Tony K" wrote:
>Thank you Michel. I'm too far into my project to re-write that much code
(9 different forms that use that connection string). I'll have to get
the
path from my customer and just recompile with that path for the
connection
string and make sure the Access DB is in that path before they use the
app.

Thank you again,

Tony K
"Michel Posseth [MCP]" <Mi**************@discussions.microsoft.comwrote
in
message news:AF**********************************@microsof t.com...
Normally when you use the designer you use the Special data directory
to
store your database ( it then becomes dynamic as the app will always
look
to the data directory regardless where it is installed )
you can recognize this by the |Data Directory| in your connection
string,
it
means that you chose to copy the mdb file into your project when you
use
the
designer to generate the connection strings.

If you want to modify it, please do not change it in the setting tab of
project property.You can achieve that by "Right Click" your table
adapter,
choose "Configure", and with two clicks of previous, you can change the
connection string.

Another option would be to concenate your own connection string , and
do
everything from code ( loose the wizards )

regards

Michel



"Tony K" wrote:

How can I customize, at runtime, the path for the OLEDB connection
uses.
I
used the Add Data Source Wizard and found the path set by the wizard
is
ReadOnly.
Aug 2 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Theerachet Pratoommanee | last post by:
This is error message I've got. Any suggestion would be appreciated. Server Error in '/WebDirectory' Application. ----------------------------------------------------------------------------...
4
by: Jenni | last post by:
Hi, A quick question. I have been battling with this code all morning, please help. Here is the code Dim fPath1 As String Dim fPath2 As String fPath1 = "C:\Program Files\Microsoft...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
1
by: Duffman | last post by:
Hi, I have what seems to be a common problem, but the solutions I've found don't seem to work. I would like to use a web service to create a file at a UNC location in a shared file. Currently...
11
by: Steve Jorgensen | last post by:
I'm working on an application in Access 2002, and every time I'm done making changes in the VBA project, the database is noticeably larger after compacting, even when code changes are small or even...
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
4
by: JOHN MALONEY | last post by:
Hi Everybody, I have created a three-tiered db application in VB .NET but I can't get the deployment to work right. I have added a SetUp project to the existing application. I also selected...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
1
by: cpajoe2001 | last post by:
I am having an issue and after searching around online for a day and half now and finding others with the same problem but yet no solution to my issue I am looking for help. What i have is ServerA...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.