Reply to topic
Global.asax and Web.config
jeffc7272


Joined: 13 May 2006
Posts: 5
Reply with quote
I'm in the process of learning aspx and am having a little trouble w/ global.asax and web.config. I think there's some fundamentals that I'm missing on how to use these files w/ the application. Here is a simple code code that I was trying to use w/ web.config for example.

<Web.config file>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="DSN" value="Provider=Microsoft.Jet.OleDb.4.0;Data Source=c:\websites\ruthqj\dn/database/dn.mdb"" />
</appSettings>
<system.web>
</system.web>
</configuration>

And an excerpt from the code that accesses it...

Dim objConn As OleDbConnection
objConn = New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))

Actually when I place the above webconfig file in the application directory I get an error page no matter what file I try to run, so obviously the problem is with the web.config file itself.

Any help is much appreciated!
bobum
Elvis Fanatic
Elvis Fanatic

Joined: 16 Nov 2004
Posts: 746
Location: Montgomery, AL
Reply with quote
well my first and most obvious question would be why are you switching slashes in the middle of a path string? I know I know it probably wont matter but it's bad practice anyway... You also have two quotes at the end of that line which will prbably throw everythign off as well... It also looks like you mivht be trying to mix ODBC connections with OLEDB connections... check out the following site for a little more direction..


connectionstrings.com
jeffc7272


Joined: 13 May 2006
Posts: 5
Reply with quote
The extra quotes were just a typo in pasting the code here, not in the actual script. The connection string is the proper string for connecting to the database on the server, but thanks anyway.

Jeff
jraybould


Joined: 29 Apr 2006
Posts: 46
Reply with quote
Assuming the file path is accurate, your connection string looks like it'd probably be fine. But to take the guess work out of it, contact support@hostmysite.com and have them create an Access DSN for you directly on the server. This will allow you to reference something that has been preconfigured to work properly. If you continue to get an error after you use a valid DSN, post the error and the pertinent code and someone on here will help you out.
jeffc7272


Joined: 13 May 2006
Posts: 5
Reply with quote
Thanks I actually got it to work. I stopped and restarted the server. Don't know if that made a difference or not, but it's working fine now. I've coded in ASP for years, but am just learning .NET. I haven't seen any references to DSNs through asp.net and they don't seem like they are commonly used (besides creating a connection string that is referenced ithrough the web.config file).

Jeff
DSNs
KyleGobel


Joined: 02 Jun 2006
Posts: 8
Reply with quote
Just curious, is creating a DSN like that faster than using the connection string everytime?

If not, then why use it? Just for cleaner code? or so you don't have to remember the connection string?

Thanks,
Kyle Gobel
jeffc7272


Joined: 13 May 2006
Posts: 5
Reply with quote
Hey Kyle, as far as saving on connection time, someone else more knowledgable will have to answer that one. I think that it probably is about the same. But, it does produce more concise code overall and one of the upsides of scripting in general is that you don't have to go in and change multiple pages (really makes sense on a large site) if you breaks things up. Because the connection script is in one file, you may have multiple pages that reference it, but you only have to make one change to the web.config file and and not go in to every single page to rewrite it.

Hope that helps
Jeff
Global.asax and Web.config
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic