473,480 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Multipart connectionstring question

Hi all,

This is a multipart question.

I’ve got an asp.net site that contains an access database. Previously, I
would debug by making changes and uploading to my host. Now, I’d like to be
able to debug locally and then deploy. I’d really like to use a relative path
for the database file (so I could make no changes between hostide and
debugging client side. When I try to use a relative path, it doesn’t seem to
be referring to the basepoint of my web application as it would for, say, an
href or src attribute. I get an exception stating:

System.Data.OleDb.OleDbException was unhandled by user code
ErrorCode=-2147467259
Message="'C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\App_Data\xc.mdb' is not a valid path. Make sure that the path
name is spelled correctly and that you are connected to the server on which
the file resides."
Source="Microsoft JET Database Engine"

The connection string I used was:

Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=App_Data\xc.mdb

I also tried

Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=\App_Data\xc.mdb

And got the same result.

On the server side, I get a different long path. I figured out how to
construct this log path into what corresponds with the base point of my
application and could hardcode the application setting. This prevents me from
running the same app both on my machine and my host without making changes. I
suppose I could use server.mappath around every DB call, but I was wondering
if there was a more elegant way to handle this situation (to get the “mapped”
path into the appsettings value the first time).

How could one even use a server.mappath with a database connection string?
As the path to the database is embedded within the connection string?

Ok, next related question. I wanted to try to take advantage of the new
ConnectionStrings feature in 2.0, so I changed my appsettings to a connection
string. (For now, I’m using a hardcoded path to test.) The connection string
works when I grab it as an appsetting, but when I try to copy it over as a
connection string and grab it with:

conXCDB = New
OleDbConnection(Server.MapPath(System.Configuratio n.ConfigurationManager.ConnectionStrings("MyMainSt ring").ConnectionString))

I get:

System.Web.HttpException was unhandled by user code
ErrorCode=-2147467259
Message="'Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\xcbackup.mdb' is
not a valid virtual path."
Source="System.Web"

Interestingly, I’m able to response.write the “ConnectionString” property to
the output and it is indeed the exact same string as before. Why now the
complaints? I used:

<add name="MyMainString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0 ;DATA
SOURCE=C:\xcbackup.mdb" providerName="System.Data.OleDB" />

I don’t know if I set the providerName properly, but I don’t know why it
would even need this as it should just be grabbing the string so I can create
a connection.

Ok, so I thought maybe I’m constructing the string incorrectly, so I try to
use the server explorer to add the connection. I choose “Microsoft Access DB
file” which chooses .NET framework data provider for OLEDB. Sounds good. I
press next, and instead of different fields for each property (filename,
timeout settings, etc), there is only one property to set:
“ConnectionString.” I try pasting my working string in there, but I get:

“Format of the initialization string does not conform to specification
startingn at index 0.”

I’ve tried adding single / double quotes, and lots of other things. I’ve
never been able to find ANY input that doesn’t give this error. Whenever I
press “test connection” it immediately reports that it sccedded. It’s when I
press “ok” that it gives me trouble. After googling around, this error seems
to have been resolved by one other by reinstalling the framework, and another
indicated that he only got this on his XP machine.

I tried another route:

I chose “other” for data source and chose “Data provider for OLEDB for data
provider.” in the next screen, I chose “MS Jet 4.0 OLEDB provider” as this is
what I was using in the string. This lets me specify properties graphically.
Under server or file name, I specify an absolute path, and leave everything
else blank. I hit ok and get an error dialog stating:

“Object reference not set to an instance of an object.”

I’ve tried filling out various values, but no matter what I do in this
dialog I get this error and am unable to proceed.

Well, that’s where I stand. I know there’s a few different questions here,
but any help would be much appreciated. Thanks guys…

-Ben

Jan 7 '06 #1
8 3369
Hi Ben,

To use a MapPath to map your database file in the connection string, you
have to

1. Map the path
2. Concatenate the path to the connection string

For example:

Dim path as String = Server.MapPath("App_Data\xc.mdb")
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + path

If you get the connection string directly from an app.config file, you
cannot pass it directly to MapPath as an argument. The argument must be a
valid path. In this case, you have to parse it yourself and re-create the
connection string with the mapped path. Or you can use different app.config
files on debug and deploy.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 9 '06 #2
Thanks for your response, Kevin. Do you have any insight regarding the
difficulty that I encountered when I tried to add the connection via the
Server Explorer? Or why I'm unable to use the connectionstring property but
am able to use an appsettings string?

Thanks Kevin...

-Ben

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

To use a MapPath to map your database file in the connection string, you
have to

1. Map the path
2. Concatenate the path to the connection string

For example:

Dim path as String = Server.MapPath("App_Data\xc.mdb")
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + path

If you get the connection string directly from an app.config file, you
cannot pass it directly to MapPath as an argument. The argument must be a
valid path. In this case, you have to parse it yourself and re-create the
connection string with the mapped path. Or you can use different app.config
files on debug and deploy.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 9 '06 #3
Hi Ben,

What do you mean by adding the connection via the Server Explorer? The
appsetting string is used to get the ConnectionString from the app.config
file. In this case, it's better to put different connection strings in
different app.config files. Then you needn't change your code when
debugging and deploying.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 10 '06 #4
Hi Kevin,

What I meant by "adding the connection via the server explorer" is:

in the Server Explorer pane: Right click Data Connections and select "Add
New Connection."

This text from my original post should describe the problem:

Ok, so I thought maybe I’m constructing the string incorrectly, so I try to
use the server explorer to add the connection. I choose “Microsoft Access DB
file” which chooses .NET framework data provider for OLEDB. Sounds good. I
press next, and instead of different fields for each property (filename,
timeout settings, etc), there is only one property to set:
“ConnectionString.” I try pasting my working string in there, but I get:

“Format of the initialization string does not conform to specification
startingn at index 0.”

I’ve tried adding single / double quotes, and lots of other things. I’ve
never been able to find ANY input that doesn’t give this error. Whenever I
press “test connection” it immediately reports that it sccedded. It’s when I
press “ok” that it gives me trouble. After googling around, this error seems
to have been resolved by one other by reinstalling the framework, and another
indicated that he only got this on his XP machine.

I tried another route:

I chose “other” for data source and chose “Data provider for OLEDB for data
provider.” in the next screen, I chose “MS Jet 4.0 OLEDB provider” as this is
what I was using in the string. This lets me specify properties graphically.
Under server or file name, I specify an absolute path, and leave everything
else blank. I hit ok and get an error dialog stating:

“Object reference not set to an instance of an object.”

I’ve tried filling out various values, but no matter what I do in this
dialog I get this error and am unable to proceed.
Thanks...

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

What do you mean by adding the connection via the Server Explorer? The
appsetting string is used to get the ConnectionString from the app.config
file. In this case, it's better to put different connection strings in
different app.config files. Then you needn't change your code when
debugging and deploying.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 10 '06 #5
Update: On my work computer running the same edition of VS 2005
(Professional), I can successfully add the db connection. Interestingly, the
dialog that I'm presented with to do so for an access file is very different
on my work machine. It has individual fields, allows me to browse for the
file, etc. The one on my other computer where it fails, only allows me to
type in a connection string. It's as though a component didn't install
properly. Is there anything I can check?

-Ben

"Ben R." wrote:
Hi Kevin,

What I meant by "adding the connection via the server explorer" is:

in the Server Explorer pane: Right click Data Connections and select "Add
New Connection."

This text from my original post should describe the problem:

Ok, so I thought maybe I’m constructing the string incorrectly, so I try to
use the server explorer to add the connection. I choose “Microsoft Access DB
file” which chooses .NET framework data provider for OLEDB. Sounds good. I
press next, and instead of different fields for each property (filename,
timeout settings, etc), there is only one property to set:
“ConnectionString.” I try pasting my working string in there, but I get:

“Format of the initialization string does not conform to specification
startingn at index 0.”

I’ve tried adding single / double quotes, and lots of other things. I’ve
never been able to find ANY input that doesn’t give this error. Whenever I
press “test connection” it immediately reports that it sccedded. It’s when I
press “ok” that it gives me trouble. After googling around, this error seems
to have been resolved by one other by reinstalling the framework, and another
indicated that he only got this on his XP machine.

I tried another route:

I chose “other” for data source and chose “Data provider for OLEDB for data
provider.” in the next screen, I chose “MS Jet 4.0 OLEDB provider” as this is
what I was using in the string. This lets me specify properties graphically.
Under server or file name, I specify an absolute path, and leave everything
else blank. I hit ok and get an error dialog stating:

“Object reference not set to an instance of an object.”

I’ve tried filling out various values, but no matter what I do in this
dialog I get this error and am unable to proceed.
Thanks...

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

What do you mean by adding the connection via the Server Explorer? The
appsetting string is used to get the ConnectionString from the app.config
file. In this case, it's better to put different connection strings in
different app.config files. Then you needn't change your code when
debugging and deploying.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 10 '06 #6
Hi Ben,

This seems to be weired. I can get the dialog for your second way, but
never get the dialog box for you to enter connection string. Maybe you can
show us a screen shot for it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 11 '06 #7
Hi Kevin,

I appreciate the offer, but I don't know of a way to attach a file via the
web news reader. I think I'll just have to be happy generating connection
strings by hand and using them manually.

Thanks again...

-Ben

"Kevin Yu [MSFT]" wrote:
Hi Ben,

This seems to be weired. I can get the dialog for your second way, but
never get the dialog box for you to enter connection string. Maybe you can
show us a screen shot for it.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 13 '06 #8
You're welcome.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Jan 16 '06 #9

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

Similar topics

34
4394
by: Niels Berkers | last post by:
Hi, i'd like to host my web pages using multiparts to reduce the number of hits on the server. i know this isn't a real PHP subject, but i'll try it anyway. i've been searching the web for...
1
1797
by: Gandalf | last post by:
Hi All! Does anyone know how to read the "multipart/form-data" posted by a form? I'm using mod_python 3.1 and Apache 2. I looked at the docs of the request object but there is no description on...
7
17248
by: Mark Waser | last post by:
Hi all, I'm trying to post multipart/form-data to a web page but seem to have run into a wall. I'm familiar with RFC 1867 and have done this before (with AOLServer and Tcl) but just can't seem...
2
10069
by: ed kool | last post by:
Question how to code "multipart/form-data in a PHP script ? We are trying to make our program trchat.exe work via the following PHP script: <?php $lang = " English to Dutch"; ...
4
3130
by: pbd22 | last post by:
hi. could somebody tell me, when uploading a file, i know the form where the upload component is must have enctype=multipart/form-data but, is the same true for the form with the server code to...
0
2764
by: sachintandon | last post by:
Hello all, Thanks in advance for your help I have a problem in sending emails, my requirement is to send multipart alternative emails with attachments, I'm able to send text with attachments or...
5
6498
by: Radu | last post by:
Hi. In a repeater I have as ItemTemplate the following, among others, and everything works great: <asp:SqlDataSource ID="LocationSqlDataSource" SelectCommand="SELECT blah-blah-blah"...
6
3110
dmjpro
by: dmjpro | last post by:
A Question was in my mind for a long day. But today suddenly knocks my mind again. So I am asking that Question here...Please Experts answer my Question. <form enctype="multipart/form-data"...
3
6035
by: jeremy.gehring | last post by:
Hey all, OK I'm not much of a PHP programmer; but needs must as they say. I have written AJAX file upload system that uses a PERL CGI script so that a PHP script can get the progress (nifty...
0
7044
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
7045
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
7087
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...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5341
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 projectplanning, coding, testing,...
1
4782
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...
0
4483
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...
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.