dataadapter wizard connection string

G

Guest

I'm trying to modify the connection string made by the dataadapter wizard to
a relative path. My current datasource is this:

""C:\Inetpub\wwwroot\database\database.mdb""

How can i change so when its on the server it will look for the directory
"database" in the root of the virtual directory?


cheers
 
G

Greg Burns

Dim cn As OleDb.OleDbConnection

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Server.MapPath(ConfigurationSettings.AppSettings("path"))) ' -->>>
c:\inetpub\wwwroot\global\data\project1.mdb

web.config...

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="path" value="/global/data/project1.mdb" />
</appSettings>

<system.web>
.... etc

HTH,
Greg
 
G

Guest

thx for the reply but i'm looking at the "web form designer generated code"
and have found the oledbdataconnections and just want to modify this. What
i'm really having problem with is the syntax.

'
'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=0;Data
Source=""C:\Inetpub\wwwroot\db\database.mdb"";Jet OLEDB:Engine " & _
"Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
database=;Jet OLEDB:S" & _
"FP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;J" & _
"et OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet OLEDB" & _
":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica Repair=Fal" & _
"se;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"


Data source - i need to change to a relative path like
server.mappath(/database/database.mdb) but everything i've tried keeps
bringing up syntax errors.
 
G

Greg Burns

Changing the desinger generated code is asking for trouble. The designer
will just overwrite it again when you least expect it.

Greg

'OleDbConnection1
'
Me.OleDbConnection1.ConnectionString = "Jet OLEDB:Global Partial
Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database L" & _
"ocking Mode=0;Data
Source=" & Server.MapPath("/db/database.mdb") & ";Jet OLEDB:Engine " & _
"Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
database=;Jet OLEDB:S" & _
"FP=False;persist security info=False;Extended
Properties=;Mode=Share Deny None;J" & _
"et OLEDB:Encrypt Database=False;Jet OLEDB:Create System
Database=False;Jet OLEDB" & _
":Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without
Replica Repair=Fal" & _
"se;User ID=Admin;Jet OLEDB:Global Bulk Transactions=1"
 
G

Guest

I realise playing around in generator code is not the smartest move, thus,
how can I make the dataadapters call a relative path to the database?
 
G

Greg Burns

John, I never use the wizards so haven't ran into this problem. My gut
response is to say you can't with the wizard (without modify its generated
output, which is BAD), but somebody will just prove me wrong. :^)

I found this article on google:
http://tinyurl.com/4uts9

It shows how to get the wizard generated code to read your web.config for
the datasource value. This avoids "messing" with the designer code
manually, but also doesn't answer your question. (In other words, not sure
how you would get Server.MapPath to act on your web.config value using this
method).

Sorry,
Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top