Webconfig Connection String

P

Paul W Smith

My application uses two ways to connect to the Access db:

Programtically:

Dim sDBPath = "Data Source=D:\MCCL\AccessDB\NewMCCL.mdb;"
Dim sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & sDBPath
Dim myConnection As New OleDbConnection(sConnString)

By Declaring:

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/NewMCCL.mdb"
SelectCommand="SELECT * FROM [web_MatchReportingByWeekID]">
</asp:AccessDataSource>


What entry do I put into my webconfig file so I can call it from within my
code?

How do I use this for both types of the above versions?

PWS
 
P

Phil H

My application uses two ways to connect to the Access db:

Programtically:

Dim sDBPath = "Data Source=D:\MCCL\AccessDB\NewMCCL.mdb;"
Dim sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & sDBPath
Dim myConnection As New OleDbConnection(sConnString)

By Declaring:

<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/NewMCCL.mdb"
SelectCommand="SELECT * FROM [web_MatchReportingByWeekID]">
</asp:AccessDataSource>

What entry do I put into my webconfig file so I can call it from within my
code?

How do I use this for both types of the above versions?

PWS

It appears from your two declarations that you have two copies of the
file NewMCCL.mdb in different locations.

Assuming that when you deploy the site it will be in "~/App_Data/
NewMCCL.mdb" it would be simpler to modify the code for sDBPath to:

sDBPath = "D:\Data Source=" & Server.MapPath("~/App_Data/
NewMCCL.mdb;")

Unless the datafile name is likely to change it isn't worth putting it
in web.config because the entries won't be the same for
AccessDataSource1 and MyConnection (the latter requires a full
connection string whereas the former only needs the datafile path).

HTH
 
G

Guest

Howdy,

web.config:

<connectionStrings>
<add name="myConnectionString"
connectionString="server=whateever;datasource=blabla"/>
</connectionStrings>

aspx page:

<asp:AccessDataSource runat="server" ID="ds"
ConnectionString="<%$ ConnectionStrings:myConnectionString %>">
</asp:AccessDataSource>


vb.net code:

Dim connectionString As String = _
ConfigurationManager.ConnectionStrings("myConnectionString").ConnectionString

ds.ConnectionString = connectionString

Hope this helps
 
P

Paul W Smith

sDBPath = "D:\Data Source=" & Server.MapPath("~/App_Data/NewMCCL.mdb;")

Are you sure about the line above, because I cannot get it to work.

Where did you get the "D:\" from?
 
M

Mark Rae [MVP]

Paul W Smith said:
Are you sure about the line above, because I cannot get it to work.

Where did you get the "D:\" from?


Maybe from the third line of your OP...?
 
P

Phil H

Are you sure about the line above, because I cannot get it to work.

Where did you get the "D:\" from?

Yes, I beg your pardon. It should have been:

sDBPath = "Data Source=" & Server.MapPath("~/App_Data/NewMCCL.mdb;")

Yours humbly
Phil Hall
 

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

Similar Threads

set parameter ms access and ? 6
WebConfig 2
Gridview Footer Help 1
MS Access connection 1
ASP and SQL Server 2005 Express 14
SQL Connection String 2
Connection String Problem 2
formview not updating record 0

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top