Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Connect to Database on web server

Status
Not open for further replies.

peekay

Programmer
Oct 11, 1999
324
ZA
My .aspx home page uses an Access database and tests correctly on my PWS, but when I deploy it to the web server it looks for the database on my C drive which of course it would not find. What do I need to change to have it look at the uploaded database on the webserver ?

Thanks


PK Odendaal
and pk@odendaal.com
 
Pk -

Try using Server.MapPath, an example for Access:

Code:
If Not IsPostBack Then
 'open database...
 Dim cmdSelect As OLEDbCommand
 Dim dbconn As OleDbConnection = New OleDbConnection( _
  "Provider=Microsoft.Jet.OLEDB.4.0; " & _
  "Data Source=" & Server.MapPath("fpdb\Sites.mdb;"))          
  cmdSelect = New OLEDbCommand("SELECT DISTINCT County FROM WebMasterSites", dbconn)
  dbconn.Open() 
  ddCty.DataSource = cmdSelect.ExecuteReader()
  ddCty.DataBind()
  dbconn.Close()        
 End If

...this is a truncated example and does not have the Try..End Try sequence (error trapping) which should be used. In your case the Server.MapPath should do the trick.
 
Thanks Isadore

I have now put in the following code and whilst it does not give me an error is also does not fill my datagrid.

Dim cmdSelect As OLEDbCommand
Dim dbCn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & "Data Source=" & Server.MapPath("WitbankPortal.mdb;"))
cmdSelect = New OleDbCommand("SELECT * from categories",dbCn)
dbCn.Open()
dgCats.DataSource = cmdSelect.ExecuteReader()
dgCats.DataBind()
dbCn.Close()

Must I not use the dataset .Fill method or a while not/loop construct ?



PK Odendaal
 
PK -

Here's a sequence loading up a DataGrid:

Code:
'open database...
Dim cmdSelect As OLEDbCommand
Dim dbconn As OleDbConnection = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & Server.MapPath("fpdb\Sites.mdb;"))          
cmdSelect = New OLEDbCommand("SELECT * FROM WebMasterSites", dbconn)
 dbconn.Open() 
 dgGroups.DataSource = cmdSelect.ExecuteReader()
 dgGroups.DataBind()  
 lblNo.Text = dgGroups.Items.Count.ToString()      
 dbconn.Close()
 dbconn = Nothing

PK - looks exactly similar to yours; hard to say, let me dig up another method you can test - it should be working, I'm sure its something small. Try writing your code exactly as it is shown above (use breaks - though that should not make a difference).

Cut and paste your DataGrid code - I'll dig up another method, post back in a few minutes.
 
PK -

Might not be related or you're already covered in this area but make sure in your Web.config file you have the proper authorization, here set to "all users":

Code:
<!--  AUTHORIZATION 
          This section sets the authorization policies of the application. You can allow or deny access
          to application resources by user or role. Wildcards: "*" mean everyone, "?" means anonymous 
          (unauthenticated) users.
    -->
    <authorization>
        <allow users="*"/> <!-- Allow all users -->

            <!--  <allow users="[comma separated list of users]"
              roles="[comma separated list of roles]"/>
            <deny  users="[comma separated list of users]"
            roles="[comma separated list of roles]"/>
            -->
    </authorization>

..and your folders are virtually available, which I'm sure they probably are.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top