Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2003, 03:49 AM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar,

The code in your example seems to be extraordinarily sensitive to any changes I make. For example, if I replace

        tblNew.Name = "Contacts"
with
    strName = "Contacts"
    tblNew.Name = strName

then the line

        .Type = adInteger
produces the error:

error 'ASP 0115'
Unexpected error
A trappable error occurred in an external object. The script cannot continue running.

(I know it happens at that line because I've put debugging Response.Writes immediately before and after it.)
 
Old December 18th, 2003, 04:26 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Are you sure you haven't changed other things as well? Stuff like this shouldn't happen.

I changed this:
Code:
tblNew.Name = "Contacts"
to this:
Code:
Dim MyTableName
MyTableName = "Contacts" 
tblNew.Name = MyTableName
without a problem.

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 18th, 2003, 02:57 PM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, this is very odd. I tried that myself this morning and it worked OK. So I tried my code again, and got the error. And now your code produces that error as well. (It's not caused by the database to-be-created already existing because I'm changing the database's name on each run. And in any case it happens after the new database creation.)

Every time I run it and get the error I end up with another mydatabasenamexx.mdb and .ldb in the relevant folder, and I can't delete them ("being used by another process") -- no doubt because my script crashed before the relevant objects were set to nothing.

Quote:
quote:Originally posted by Imar
 Are you sure you haven't changed other things as well? Stuff like this shouldn't happen.

I changed this:
Code:
tblNew.Name = "Contacts"
to this:
Code:
Dim MyTableName
MyTableName = "Contacts" 
tblNew.Name = MyTableName
without a problem.

Imar



---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 18th, 2003, 03:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Welcome to the odd world of ADOX programming ;) It's not as intuitive as other (Microsoft) object models.

Apparently, the code crashes somewhere, so the locks to the files are never released. You need to find out what code is causing the error. Alternatively, you can create your own Try Catch Finally block ;) Set On Error Resume Next, and then make sure you still set all objects to nothing.

Not an elegant solution, but it might help to release the resources.

What kind of modifications are you making? Maybe you can post some code so I can take a look at it......

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old December 19th, 2003, 01:23 AM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 What kind of modifications are you making? Maybe you can post some code so I can take a look at it......
Well, I've taken out just about everything that I added and it still crashes with that error, just at a later point in the processing now. Here's what's in the ASP. I've omitted routine html that comes before and after this, and I've changed the path to "path" to help protect the guilty.

When it's in a good mood it crashes somewhere after the line
        Response.Write "<p>Have done the Appends. Now set the adColNullables.</p>"

If I try running it again after that crash (with a different database, because now there's alocked version of the first one in the directory), then it crashes much earlier, at the line:

        .Type = adInteger

The ASP:

<%

Dim pagename, dox_folder, dbfilename_execdirs, dbfilename_public, dbname_execdirs, dbname_public

pagename = "filter-main2public.asp" ' change these when renaming the page, etc

dox_folder = "d:\path\dox\"
dbfilename_execdirs = "execdirs.xls"
dbfilename_public = "MembersPublic.mdb"
dbname_execdirs = dox_folder & dbfilename_execdir
dbname_public = dox_folder & dbfilename_public

                ' create new database

Sub CreateAccessDatabase(sDatabaseToCreate)
    Dim catNewDB ' As ADOX.Catalog
    Set catNewDB = Server.CreateObject("ADOX.Catalog")
    catNewDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & sDatabaseToCreate & _
        ";Jet OLEDB:Engine Type=5;"
    ' Engine Type=5 = Access 2000 Database
    ' Engine Type=4 = Access 97 Database
    Set catNewDB = Nothing
End Sub

            ' create table in database
Sub CreateAccessTable(sDatabaseToCreate)
    ' Dim tblName
    ' tblName = "Members"
    Dim catDB ' As ADOX.Catalog
    Set catDB = Server.CreateObject("ADOX.Catalog")
    ' Open the catalog
    catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & sDatabaseToCreate
    Dim tblNew ' As ADOX.Table
    Set tblNew = Server.CreateObject("ADOX.Table")
    ' tblNew.Name = tblName
        tblNew.Name = "Members"

        Response.Write "<p>will now create the autonumber column</p>"

    ' First Create an Autonumber column, called WebID.
    ' This is just for demonstration purposes.
    ' We could have done this below with all the other columns as well
    Dim col ' As ADOX.Column
    Set col = Server.CreateObject("ADOX.Column")

            Response.Write "<p>Created the ADOX.Column object 'col'</p>"
    With col
        .ParentCatalog = catDB
            Response.Write "<p>Assigned the ParentCatalog property</p>"
            Response.Write "<p>adInteger = " & adInteger & "</p>"
        .Type = adInteger
            Response.Write "<p>Assigned the Type</p>"
        .Name = "WebID"
            Response.Write "<p>Assigned the Name</p>"
        .Properties("Autoincrement") = True
    End With

        Response.Write "<p>Have done the assignments, now do the Append method</p>"

    tblNew.Columns.Append col

        Response.Write "<p>will now create the other columns</p>"

    ' Now add the rest of the columns
    With tblNew
        ' Create fields and append them to the
        ' Columns collection of the new Table object.
        With .Columns
            .Append "Execdir_ID", adInteger
            .Append "LastName", adVarWChar
            .Append "Suffix", adVarWChar
            .Append "FirstName", adVarWChar
            .Append "MembershipClass", adVarWChar
            .Append "HomePage", adVarWChar
            .Append "SFFNet_Newsgroup", adVarWChar
            .Append "Blog", adVarWChar
            .Append "BFOB", adVarWChar
            .Append "Calendar", adVarWChar
        End With

        Response.Write "<p>Have done the Appends. Now set the adColNullables.</p>"


        Dim adColNullable, adColFixed ' Is not defined in adovbs.inc,
            ' so we need to define it here.
            ' The other option is adColFixed (ie: required field) with a value of 1
        adColFixed = 1
        adColNullable = 2
            .Columns("WebID").Attributes = adColFixed
            .Columns("Execdir_ID").Attributes = adColFixed
            .Columns("LastName").Attributes = adColFixed
        .Columns("Suffix").Attributes = adColNullable
        .Columns("FirstName").Attributes = adColNullable
        .Columns("MembershipClass").Attributes = adColNullable
        .Columns("HomePage").Attributes = adColNullable
        .Columns("SFFNet_Newsgroup").Attributes = adColNullable
        .Columns("Blog").Attributes = adColNullable
        .Columns("BFOB").Attributes = adColNullable
        .Columns("Calendar").Attributes = adColNullable
    End With

    ' Add the new Table to the Tables collection of the database.
    catDB.Tables.Append tblNew
    Set col = Nothing
    Set tblNew = Nothing
    Set catDB = Nothing
End Sub

            ' ***** ACTUAL PROGRAM EXECUTION STARTS HERE *****

' First check if database exists, and rename it if it does
'Dim objFSO, objFolder, objFile
'Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objFolder = objFSO.GetFolder(dox_folder)
'For Each objFile in objFolder.Files
' If objFile.Name = "MembersPubOld.mdb" Then
' Response.Write "<p>deleting MembersPubOld.mdb</p>"
' objFile.Delete
' End If
'Next
'For Each objFile in objFolder.Files
' If objFile.Name = "MembersPublic.mdb" Then
' Response.Write "<p>renaming (moving) MembersPublic.mdb</p>"
' objFile.Move "MembersPubOld.mdb"
' End If
'Next

'Set objFSO = nothing
'Set objFolder = nothing
'Set objFile = nothing

' First call the Create Database method
Response.Write "<p>Calling the Create Database routine</p>"
CreateAccessDatabase dbname_public

' Then add a table and columns to this database
Response.Write "<p>Calling the Create Table routine</p>"
CreateAccessTable dbname_public
Response.Write "Database has been created successfully!"

%>
 
Old December 19th, 2003, 01:29 AM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

By the way, Imar, I found one bona fide error in your code: You use "col" (lowercase) but at the end you set "Col" (capitalized) to nothing.

-- Graham
 
Old December 19th, 2003, 01:39 AM
gpc gpc is offline
Authorized User
 
Join Date: Dec 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One other question: Since my goal is to set up and manipulate some databases online, would I be better off doing all this with SQL Server databases instead of Access? In searching for help online I found one page that urged the use of SQL Server for anything web-based, instead of using a "file-based" database such as Access. The rationale being to avoid ODBC and use OLE-DB instead, which is claimed to be more reliable and faster than ODBC, but I have no idea if that's really just a religious preference.

-- Graham
 
Old December 19th, 2003, 10:24 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I would recommend going with MS-SQL server if you can. It's going to be much more reliable/stable/faster than access and you won't have to deal with the file system security issues that you do with access. Granted you'll need to deal with SQL security, but that's usually a lot less finicky.

My suggestion earlier about connecting to "master" will work for you with SQL. You can connect (with proper privileges) to SQL's "master" database and from there can create new databases.

BTW- In ASP using VBScript, case sensitivity is not enforced so Col=col

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i create a new ado database ? jerryham VB.NET 8 October 13th, 2008 09:21 PM
Ex0201 - Create Database khempire C# 2 January 14th, 2008 08:26 PM
Unable to create database. rupen SQL Server 2005 4 December 6th, 2007 02:39 AM
How to create a Database koushikroy2001 SQL Language 2 January 4th, 2006 04:03 AM
Create database Yee MySQL 2 November 5th, 2004 06:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.