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

Home Posts Topics Members FAQ

connection string on web.config

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 :)
Nov 19 '05 #1
2 1328
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" <no****@nospam.com> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl...
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 :)

Nov 19 '05 #2
How can I reference a class in my code.
Need sample code, please.

Thanks :)

"Joel Leong" <ch******@hotmail.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
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" <no****@nospam.com> wrote in message
news:eZ**************@TK2MSFTNGP14.phx.gbl...
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 :)


Nov 19 '05 #3

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

Similar topics

3
2126
by: Varun | last post by:
I have a solution which contains windows,web,mobile presentations. Now i want to share the connection string in the web.config file. i want to write a method in a common layer where i can retrieve...
6
2132
by: H | last post by:
This is a question that has haunted me for quite some time. if you build a 4 tier database application where the 4th tier is the database server (MS SQL 2000), where do you build the connection...
6
1766
by: Jon Davis | last post by:
I like the drag-and-drop accessibility of dragging a table to a Web Forms designer and seeing a SqlDataAdapter automatically created for me.. being able to create a DataSet from that is fun and...
6
1490
by: Mike L. | last post by:
Hi, Pls, beware that I'm new to this :) I've developed several web appl, either with ASP or ASP.NET. All using SQL server as the back end. In my development environment, I have a single...
19
2506
by: Jaime Stuardo | last post by:
Hi all.. I have created a business logic component that is used from my ASP.NET webform. It works, but connection string to the database is hard coded, as in this method : public DataSet...
14
3480
by: WebMatrix | last post by:
Hello, I have developed a web application that connects to 2 different database servers. The connection strings with db username + password are stored in web.config file. After a code review,...
9
2756
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have a question about storing the connection strings to the database in a config file or database. My manager wants me to store all the connection strings in a database, but I...
2
6591
by: Thorsten Dittmar | last post by:
Hi, I don't get it. I'm using a typed dataset with table adapters and all that stuff. I have the database server running locally on my development system. Now: when creating a tableadapter...
8
6318
by: Brett | last post by:
I wrote an ASP.NET application that queries a SQL Server database (on a different box from the web server) and displays the result in a GridView. The datasource for the GridView is a SQLDataSource....
2
5358
by: Johnson | last post by:
I'm trying to fix a "sub optimal" situation with respect to connection string management. Your thoughtful responses will be appreciated. I just started with a new client who has a bunch of legacy...
0
7046
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
7048
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
7088
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...
1
6741
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...
0
5342
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,...
0
4485
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
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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 ...

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.