Last post Apr 05, 2008 03:28 PM by Mikesdotnetting
Apr 05, 2008 02:11 PM|anarine|LINK
I have a number of pages on my site that access a msaccess database.
The problem is when I change the location of the database, I have to go to Each webpage and update the Datafile path. Is there a
way to set the path centrally in one place ? So that when I update that file, all the webpages will pull that update, perhaps some kind
of variable I dont know..
Here is the line in asp that I have to change for each and every page that uses the database:
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="e:\databases\na644\ASPNetDB.mdb"
I don't want to have to go to each page and change the DataFile path.
Apr 05, 2008 02:24 PM|Mikesdotnetting|LINK
You can add it to the web.config and set it at runtime in the code behind in each page, or better still, ditch the AccessDataSource control and use the SqlDataSource control instead, and set the connection string in the web.config.
Apr 05, 2008 02:53 PM|anarine|LINK
Can you give me an example?
That would really help!
Apr 05, 2008 02:55 PM|anarine|LINK
I really dont want to change from the accessdatasource, I have many pages to update.
Apr 05, 2008 03:05 PM|Mikesdotnetting|LINK
In your web.config, you would put the full path to the database in the appsettings section:
<add key="conn" value="<full path to db>/Northwind.mdb" />
Then reference it in the AccessDataSource control like this:
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ appSettings:conn %>" SelectCommand="SELECT * FROM SomeTable">
You won't be able to set this using the configuration wizard, which means you will have to do it manually. But once it's done, you only need to change the web.config in the event of a db move or name change.
Frankly, the AccessDataSource control doesn't seem to me to be particularly well thought through. That's why I would never use it. I would always choose the SqlDataSource control. The other thing about the Access version is that it doesn't work with Access
2007, because internally, it will only use the Jet provider. 2007 uses the ACE provider.
Apr 05, 2008 03:21 PM|anarine|LINK
For my general knowledge,
<%$ appSettings:conn %>
the $ means this is a variable right ?
<% %> what is this called ? I've never used this kind of notation before in asp.
Apr 05, 2008 03:28 PM|Mikesdotnetting|LINK
<% %> are the delimiters used for inline code or expressions in ASP.NET.