Webconfig Connection String

  • Thread starter Thread starter Paul W Smith
  • Start date Start date
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
 
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
 
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
 
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?
 
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...?
 
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
 
Back
Top