Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > connection string on web.config

Reply
Thread Tools

connection string on web.config

 
 
eitan
Guest
Posts: n/a
 
      06-03-2005
Hello,
I put the following code in web.config

<appSettings>

<add key="ConnectionString"

value='PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
Source=Server.MapPath("/db/mydb.mdb")' />

</appSettings>



The code is wrong.

In vb code, I wanted to do :

conMain.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionStrin g")

(where conMain is oleDB.oleConnection)

but the connectionString was wrong.

So, what I did is :

conMain.ConnectionString = "provider = microsoft.jet.oledb.4.0; data source
= " _

& Server.MapPath("./db/mydb.mdb")


Can I do it otherwise ?

Can I just put in vbscript/javascript (server code),

and reference the code at the aspx page ?

How can I do that ?



Thanks


 
Reply With Quote
 
 
 
 
Joel Leong
Guest
Posts: n/a
 
      06-04-2005
You can't do that.

The easiest way is remove the server.mappath function,
create a class with static method, inside this method, get the 'source'
token and then
use server.mappath to change the /db/mydb.mdb. Return the new connection
string from this method.
So everytime you need connectionstring, just call the static method.

"eitan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> I put the following code in web.config
>
> <appSettings>
>
> <add key="ConnectionString"
>
> value='PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
> Source=Server.MapPath("/db/mydb.mdb")' />
>
> </appSettings>
>
>
>
> The code is wrong.
>
> In vb code, I wanted to do :
>
> conMain.ConnectionString =
> ConfigurationSettings.AppSettings("ConnectionStrin g")
>
> (where conMain is oleDB.oleConnection)
>
> but the connectionString was wrong.
>
> So, what I did is :
>
> conMain.ConnectionString = "provider = microsoft.jet.oledb.4.0; data
> source = " _
>
> & Server.MapPath("./db/mydb.mdb")
>
>
> Can I do it otherwise ?
>
> Can I just put in vbscript/javascript (server code),
>
> and reference the code at the aspx page ?
>
> How can I do that ?
>
>
>
> Thanks
>
>



 
Reply With Quote
 
 
 
 
Eitan
Guest
Posts: n/a
 
      06-04-2005
How can I reference a class in my code.
Need sample code, please.

Thanks

"Joel Leong" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You can't do that.
>
> The easiest way is remove the server.mappath function,
> create a class with static method, inside this method, get the 'source'
> token and then
> use server.mappath to change the /db/mydb.mdb. Return the new connection
> string from this method.
> So everytime you need connectionstring, just call the static method.
>
> "eitan" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hello,
>> I put the following code in web.config
>>
>> <appSettings>
>>
>> <add key="ConnectionString"
>>
>> value='PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
>> Source=Server.MapPath("/db/mydb.mdb")' />
>>
>> </appSettings>
>>
>>
>>
>> The code is wrong.
>>
>> In vb code, I wanted to do :
>>
>> conMain.ConnectionString =
>> ConfigurationSettings.AppSettings("ConnectionStrin g")
>>
>> (where conMain is oleDB.oleConnection)
>>
>> but the connectionString was wrong.
>>
>> So, what I did is :
>>
>> conMain.ConnectionString = "provider = microsoft.jet.oledb.4.0; data
>> source = " _
>>
>> & Server.MapPath("./db/mydb.mdb")
>>
>>
>> Can I do it otherwise ?
>>
>> Can I just put in vbscript/javascript (server code),
>>
>> and reference the code at the aspx page ?
>>
>> How can I do that ?
>>
>>
>>
>> Thanks
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to set the connection pool size in the Sybase connection string? Wei Lu ASP .Net 2 02-16-2009 09:51 AM
Web.config: connection string or connection key? rlueneberg@gmail.com ASP .Net 3 08-03-2007 09:37 PM
Connection String object Convert to String Variable Type =?Utf-8?B?TWlrZSBNb29yZQ==?= ASP .Net 2 10-26-2004 02:43 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM
connection string exception : Format of the initialization string does not conform to specification starting at index 0 Gaurav ASP .Net 0 11-07-2003 10:24 AM



Advertisments