Results 1 to 4 of 4

Thread: Database connections

  1. #1

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    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:
    1. Dim strOle As String = "db/imagegallery.mdb"
    2. 'where db is the name of your folder holding the access database
    3. Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;
    4. Data Source=" & Server.MapPath(strOle))
    5. '...........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

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  3. #3

    Thread Starter
    Hyperactive Member Rocketdawg's Avatar
    Join Date
    Feb 2003
    Location
    Back in the doghouse
    Posts
    294

    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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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
  •  



Click Here to Expand Forum to Full Width