473,594 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing the place of a Database

Hello,

I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.

Thanks in advance.

Luis
Nov 20 '05 #1
7 1392
* "Luis Mendes" <an*******@disc ussions.microso ft.com> scripsit:
I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.


What's the problem? How do you connect to the database?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
Hi Luis,
herfried is much more experienced than me but let me throw my two cents in.
Listen to Herfried though as he knows a lot more than I do.

What you can do is assign a string to the database path the user chooses
through an open file dialog box. Make sure you make it a public variable so
you can use it throughout your application.
Assuming the public string is called "databasepa th" your connection string
could then look like this:

Dim sConn As New OleDb.OleDbConn ection
sConn.Connectio nString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" & databasepath & _
";Password= ;Jet OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Jet.OLEDB .4.0"";Je" & _
"t OLEDB:System database=;Jet OLEDB:SFP=False ;Extended
Properties=;Mod e=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False; J" & _
"et OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact Without
Replica Re" & _
"pair=False;Use r ID=Admin;Jet OLEDB:Encrypt Database=False"

"Luis Mendes" <an*******@disc ussions.microso ft.com> wrote in message
news:08******** *************** *****@phx.gbl.. .
Hello,

I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.

Thanks in advance.

Luis

Nov 20 '05 #3
Cor
Hi Scorpion,

The problem with this is that if you have made your connection string by
hand, you can do everything you want with it.

But when you use the generic tools, as far as I know till now, you cannot do
anything with it.

The sequence in that part is something like:
- connection string
- open connection

And you cannot come between that in the designer part.
When you change something, the designer corrects it full automatically for
you, if you want to change the slightest thing, the next time.

Therefore I think that designer thing is useless for commercial software.
Inside an organisation it will maybe work, if you are able to put from the
start on your database on the end place.

I follow this kind of messages like a hawk, but I have seen no good answer
till now.

Cor
Nov 20 '05 #4
Sorry you didnt like it.

I just took the code generated with the creation of the connection string
and replaced the path with the database variable.
xml file loaded at startup provides this info.

The only downside that I have encountered is you can't put it in a module as
I kept getting intialization errors. You might have a thought on that I
could use.

I had to do encryption(the whole string and then grabbing it out of an xml
file) to deal with the password problem in SQL and when one was required in
access but it worked. Sorry for the unnecessary code that is here but it is
what I had opened at the time.

'xml file for user choice of connection
<?xml version="1.0" encoding="utf-8" ?>
<Section Name="Settings" >
<Key Name="databasep ath" Value="C:\datab ase.mdb"/> 'user fills this when
using open dialog box
</Section>

Loading the file at startup of app....

Private Sub ReadXmlConfig()
' Create Xml Document and load the xml file
Dim xmlDoc As XmlDocument = New XmlDocument
xmlDoc.Load("C: \Neumann Plumbing and Heating\XMLDBPA TH.xml") 'can
use appdirectory when finished with project.
' Read mail server value
Dim keyNodeList As XmlNodeList =
xmlDoc.Document Element.SelectN odes("Key")
Dim keyNode As XmlNode
For Each keyNode In keyNodeList
' Read the attributes...
Dim attribs As XmlAttributeCol lection = keyNode.Attribu tes
Dim attrib As XmlAttribute = attribs("Name")
If attrib.Value = "databasepa ths" Then
databasepath = attribs("Value" ).Value.ToStrin g()
'MsgBox(databas epath)
End If
Next
End Sub

Using the connection:

Sub GetComboBoxFill s()
Dim sConn1 As New OleDb.OleDbConn ection
sConn1.Connecti onString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" &
databasepath & _
";Password= ;Jet OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Jet.OLEDB .4.0"";Je" & _
"t OLEDB:System database=;Jet OLEDB:SFP=False ;Extended
Properties=;Mod e=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False; J" & _
"et OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact
Without Replica Re" & _
"pair=False;Use r ID=Admin;Jet OLEDB:Encrypt Database=False"

Dim itemcheck As Integer
Dim dscustomers2 As DataSet 'customer company
'more datasets not relevant here

dscustomers2 = Dscustomers1.Cl one

Dim SQL3 As String
'more strings not relevant here

SQL3 = "SELECT DISTINCT CustCompanyName FROM CUSTOMERS order by
CustCompanyName "
dscustomers2.En forceConstraint s = False

Dim OleDbCUSTCOMPAN Y As New OleDb.OleDbData Adapter 'customer COMPANY
OleDbCUSTCOMPAN Y = OleDbDBCUST

OleDbCUSTCOMPAN Y = New OleDb.OleDbData Adapter(SQL3, sConn1)

OleDbCUSTCOMPAN Y.Fill(dscustom ers2.Tables(0))
'more fills not relevant here

dscustomers2.Ac ceptChanges()

sConn1.Close() 'very important

"Cor" <no*@non.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Hi Scorpion,

The problem with this is that if you have made your connection string by
hand, you can do everything you want with it.

But when you use the generic tools, as far as I know till now, you cannot do anything with it.

The sequence in that part is something like:
- connection string
- open connection

And you cannot come between that in the designer part.
When you change something, the designer corrects it full automatically for
you, if you want to change the slightest thing, the next time.

Therefore I think that designer thing is useless for commercial software.
Inside an organisation it will maybe work, if you are able to put from the
start on your database on the end place.

I follow this kind of messages like a hawk, but I have seen no good answer
till now.

Cor

Nov 20 '05 #5
Hi,

I just want to ask why you would want to do this instead
of setting a system DSN. The problem I have with this is
you have to rebuild your app every time you make a change
your path or even database password

Another alternative may be going back to the old ini file
(text file), which you can upload onto users machines upon
change without recompiling your source and reinstalling on
user machines.

I've had to go with system dsn so far, but haven't found a
more flexible option.
-----Original Message-----
Hi Luis,
herfried is much more experienced than me but let me throw my two cents in.Listen to Herfried though as he knows a lot more than I do.
What you can do is assign a string to the database path the user choosesthrough an open file dialog box. Make sure you make it a public variable soyou can use it throughout your application.
Assuming the public string is called "databasepa th" your connection stringcould then look like this:

Dim sConn As New OleDb.OleDbConn ection
sConn.Connectio nString = "Jet OLEDB:Global Partial Bulk Ops=2;JetOLEDB:Regist ry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source=" & databasepath & _";Password=;Je t OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1 ;Provider=""Mic rosoft.Jet.OLED B.4.0"";Je" & _"t OLEDB:System database=;Jet OLEDB:SFP=False ;Extended
Properties=;Mo de=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create SystemDatabase=False ;J" & _
"et OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact WithoutReplica Re" & _
"pair=False;Us er ID=Admin;Jet OLEDB:Encrypt Database=False"
"Luis Mendes" <an*******@disc ussions.microso ft.com> wrote in messagenews:08******* *************** ******@phx.gbl. ..
Hello,

I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.

Thanks in advance.

Luis

.

Nov 20 '05 #6
You are right Mike.

It is not efficient. But it is one that allows me to be able to completely
control what happens when the connection is called on another users machine.

If this stayed on my machine and was going no further yes you are right DSN
is the way to go. But the end users environment is very hard to predict what
will happen. This method lets them control the location and allows me full
control over the other aspects of the connection.

The other problem I encountered was when I needed to hide a password. With
encryption, I could hide it sufficinetly. Other methods I found lacking.

"Mike" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. .
Hi,

I just want to ask why you would want to do this instead
of setting a system DSN. The problem I have with this is
you have to rebuild your app every time you make a change
your path or even database password

Another alternative may be going back to the old ini file
(text file), which you can upload onto users machines upon
change without recompiling your source and reinstalling on
user machines.

I've had to go with system dsn so far, but haven't found a
more flexible option.
-----Original Message-----
Hi Luis,
herfried is much more experienced than me but let me

throw my two cents in.
Listen to Herfried though as he knows a lot more than I

do.

What you can do is assign a string to the database path

the user chooses
through an open file dialog box. Make sure you make it a

public variable so
you can use it throughout your application.
Assuming the public string is called "databasepa th" your

connection string
could then look like this:

Dim sConn As New OleDb.OleDbConn ection
sConn.Connectio nString = "Jet OLEDB:Global

Partial Bulk Ops=2;Jet
OLEDB:Regist ry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source="

& databasepath & _
";Password=;Je t OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1 ;Provider=""Mic rosoft.Jet.OLED B.4.0"";Je" &

_
"t OLEDB:System database=;Jet OLEDB:SFP=False ;Extended
Properties=;Mo de=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create

System
Database=False ;J" & _
"et OLEDB:Don't Copy Locale on Compact=False;J et

OLEDB:Compact Without
Replica Re" & _
"pair=False;Us er ID=Admin;Jet OLEDB:Encrypt

Database=False"

"Luis Mendes" <an*******@disc ussions.microso ft.com> wrote

in message
news:08******* *************** ******@phx.gbl. ..
Hello,

I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.

Thanks in advance.

Luis

.

Nov 20 '05 #7
Mike,
You would not have to "rebuild" the app. The location of the database is set
in a xml file and is loaded on form load. The connection string will then
contain that variable as the physical location of the database.
"Mike" <an*******@disc ussions.microso ft.com> wrote in message
news:0a******** *************** *****@phx.gbl.. .
Hi,

I just want to ask why you would want to do this instead
of setting a system DSN. The problem I have with this is
you have to rebuild your app every time you make a change
your path or even database password

Another alternative may be going back to the old ini file
(text file), which you can upload onto users machines upon
change without recompiling your source and reinstalling on
user machines.

I've had to go with system dsn so far, but haven't found a
more flexible option.
-----Original Message-----
Hi Luis,
herfried is much more experienced than me but let me

throw my two cents in.
Listen to Herfried though as he knows a lot more than I

do.

What you can do is assign a string to the database path

the user chooses
through an open file dialog box. Make sure you make it a

public variable so
you can use it throughout your application.
Assuming the public string is called "databasepa th" your

connection string
could then look like this:

Dim sConn As New OleDb.OleDbConn ection
sConn.Connectio nString = "Jet OLEDB:Global

Partial Bulk Ops=2;Jet
OLEDB:Regist ry Path=;Jet OLEDB:Database L" & _
"ocking Mode=1;Jet OLEDB:Database Password=;Data Source="

& databasepath & _
";Password=;Je t OLEDB:Engine T" & _
"ype=5;Jet OLEDB:Global Bulk
Transactions=1 ;Provider=""Mic rosoft.Jet.OLED B.4.0"";Je" &

_
"t OLEDB:System database=;Jet OLEDB:SFP=False ;Extended
Properties=;Mo de=Share Den" & _
"y None;Jet OLEDB:New Database Password=;Jet OLEDB:Create

System
Database=False ;J" & _
"et OLEDB:Don't Copy Locale on Compact=False;J et

OLEDB:Compact Without
Replica Re" & _
"pair=False;Us er ID=Admin;Jet OLEDB:Encrypt

Database=False"

"Luis Mendes" <an*******@disc ussions.microso ft.com> wrote

in message
news:08******* *************** ******@phx.gbl. ..
Hello,

I've a application in VB.NET that uses a connection to a
Access data base stored in my Hard Drive.

How can I change the location of the database (To a
network) and change the conection string?

In VB6 this was very easy, but under VB.NET I'm not able
to do it.

Thanks in advance.

Luis

.

Nov 20 '05 #8

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

Similar topics

8
4842
by: Rob | last post by:
Hi all, Is it possible to change the Session.LCID in a hyperlink? My problem is I'm calling a Date from a database to use as a querystring in the hyperlink but I also need to display the date as output from the hyperlink. I need to have to querystring in Session.LCID = 1033 and the display date in Session.LCID = 2057. Coding :-
4
13100
by: Bruce | last post by:
I need to create a stored procedure in the master database that can access info to dynamically create a view in another database. It doesn't seem like it should be very hard, but I can't get it to work. Here's an example of what I want to do. CREATE PROCEDURE create_view @dbname sysname AS BEGIN DECLARE @query varchar(1000) SELECT @query = 'use ' + @dbname + ' go CREATE VIEW ........'
7
1724
by: Alex Hunsley | last post by:
I'm aware of how to access the document model in Javascript in order to do things like change the values in the fields forms. However, I'd like to pop up a helper window seperate from the page containing the form, and when the user makes a selection and hits an 'ok' button in the pop-up, I'd like their selectiont to be inserted into a field on a form in the main window. Is this possible? thanks alex
13
2899
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify the field type when running a make table query? Thanks, Sven
16
2433
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables (se below) then I run a query giving me a running total, which give me the first stock in the batch purchased by an individual, then I use this number and add the number of shares in order to find the number of the individuals' last share. So...
5
2461
by: David Deacon | last post by:
Hi i was given the following advise,below my OriginalQuestion I am a little new to ADOX can you direct me to the following Do i place the code behind a button on a form? Or do i place it in the On Open event and have a the default 10% and give the user the option to change it to 0% I have referenced th appropriate library and the default value of the field to change is 0.1
2
2056
by: S P Arif Sahari Wibowo | last post by:
Hi! Do you know how to put a form's Access-Visual-Basic-code that will force the form to be inserted, while the user has not type anything in the form, without changing focus, selection, etc.? Here is the story. I have this structure:
1
2808
by: SurfCoder | last post by:
Scenario: i have a little programm that uses OleDb.connection to connect to a database... the datasource is C:\programm Files\Database.mdb now i want to change the datasource for the connection while i am reading the datasource string from a file !!!! Cause the user want to put the database a place i dont noe yet!!!(e.g a fileserver on the network!) Code: private void Form1_Load(object sender, System.EventArgs e) {
5
2582
by: marton | last post by:
Hi there, I'm new to posting on the forum, and I've been working with MS Access for a couple of years, but and other than that know nothing about programming. I have a fairly simple, networked, Access database created with Access 2003. It is accessed from several different computers in my department (I don't know which computers or how often). About 8 people are entering data with an unbound form (which also records computer ID, date and...
0
7946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7877
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8253
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8009
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5411
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1482
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1216
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.