|
-
Jun 14th, 2005, 10:15 AM
#1
Thread Starter
Hyperactive Member
Database connections
* Resolved *
Sure is easier doing this on the localhost. Since I can't delete the post...... If anyone was looking for a
generic sort of connection, this is what worked.
VB Code:
Dim strOle As String = "db/imagegallery.mdb"
'where db is the name of your folder holding the access database
Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;
Data Source=" & Server.MapPath(strOle))
'...........and on to the command
Originally the connection was in web.config and the db functions in a separate class.
Last edited by Rocketdawg; Jun 14th, 2005 at 01:53 PM.
Reason: Resolved
-
Jun 15th, 2005, 02:02 AM
#2
Re: Database connections

You should've left your original post intact, and replied to the thread with what you did to solve it.
It makes very little sense at the moment.
-
Jun 15th, 2005, 07:01 AM
#3
Thread Starter
Hyperactive Member
Re: Database connections
Mendhak
You're right. Originally on my machine, the connection string was in Web.Config like this:
Code:
<appSettings>
<add key="DSN" value="Provider=Microsoft.Jet.OleDb.4.0;Data Source=D:\Inetpub\wwwroot\MyWeb\db\images.mdb" />
</appSettings>
I created a class modeled after the Microsoft Commerce Kit that had functions to return info from an access database like this:
Code:
Public Class ImagesDB
Public Function GetImageCategories() As OleDbDataReader
Dim conn As OleDbConnection = New OleDbConnection(ConfigurationSettings.AppSettings("DSN"))
Dim mycmd As OleDbCommand = New OleDbCommand("SELECT Category, Count(Category) AS Totals FROM Images GROUP BY Category", conn)
conn.Open()
Dim result As OleDbDataReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection)
Return result
End Function
End Class
Then in the form load event of the webforms I instantiated the class and passed the result to datalists and/or repeaters.
I wasn't sure how to connect to my database once I moved the website to EasyCGI (my host). I knew where and to what folder to FTP the database.
Since Web.Config is XML and I didn't know the actual path, I figured I would use a virtual path in the class. I'm a noob, so I rely on intellisense alot to let me know if something will work. I tried typing Server. in the class, but nothing popped. Crap.
That's when I wrote the original post.. I decided to move the database functions to the pages that called for them and scrap the separate class.
Cliff
BTW Mendhak, your site's design is great.
-
Jun 15th, 2005, 07:08 AM
#4
Re: Database connections
Thanks. 
But hold on a minute, what does the location of web.config matter in your code? Even if you move the files to your host, web.config will be in the root folder of your application. Your code should work just fine!
Originally, you put the entire path, D:\inetpub\ blah blah blah.
You can simply put the relative path (foldername\abc.mdb) and then use Server.MapPath(ConfigurationSettings.AppSettings("DSN")).
Although you have the solution now, try doing what I just told you to. It's better practice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|