Create MDB in ASP.NET 2

  • Thread starter Thread starter Edwin Knoppert
  • Start date Start date
If you absolutely have to do this in Net 2 (or Net 1 for that matter), then
you will have to use the ADOX com dll. Following is a function that does it.
You have to reference the ADOX 2.8 dll, probably add an imports (or using)
ADOX. There are no native Net framework class to create Jet databases or
tables. You (as well as I) have to consider migrating to SQLExpress 2005.

Private Function ADOCreateAccessDatabase(ByVal strDBPath As String) As
ADOX.Catalog

Dim catNewDB As ADOX.Catalog

Try

catNewDB = New ADOX.Catalog

catNewDB.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & _

"Data Source=" & strDBPath & "\userdata.mdb")

Catch ex As Exception

MsgBox("ADOCreateAccessDatabase error:" & vbCrLf & ex.Message,
MsgBoxStyle.Exclamation)

catNewDB = Nothing

End Try

Return catNewDB

End Function
 
The on the fly creation is an issue for downloading MDB's for our customers.
Iow, where must provide such a system.
I was aware of the com variant, thanks.
Currently i make use of an empty db i copy.

Is there an easy way i can embed the db in my dll (assembly) ?
I have no problem putting it into an resource but i don't know how.

To compile my database.cs i drop it on a bat file which calls the compiler
(i'm working VWD express, therefore :) )

Is it possible to extend this bat to combine a (RCDATA kind of) resource ?

Modularity rules...

Thanks,
 
Hmm, the sentence is incorrect but i was trying to explain that data needs
to be copied into an empty database for downloading purposes.

The select stuff i messed with earlier works fine, only there is no db
created, for xls output oledb creates an xls by itself.
To bad..

Maybe a CREATE TABLE IN.. situation.. we'll see.
 
If I need to generate Access DBs on the fly I use one of two methods. First
is to use the ADOX libraries. However, this can be a nuisance as is it not
a core .NET library. My favoured method is rather simple. Create a blank
database and distribute it with the application / web site. When you need a
new database, simply make a file copy of the blank one. (Told you it was
simple but it works!)
 
Currently i make use of an empty db i copy.
:)


BlackWasp said:
If I need to generate Access DBs on the fly I use one of two methods.
First is to use the ADOX libraries. However, this can be a nuisance as is
it not a core .NET library. My favoured method is rather simple. Create
a blank database and distribute it with the application / web site. When
you need a new database, simply make a file copy of the blank one. (Told
you it was simple but it works!)
 
Edwin,
If by some chance you are using NET 2.0 and NET 2005, there is a bootstrap
function in the properties that will attach the empty database to your
project (or full database for that matter) and this is done by just adding
the database to the setup project. If it is a NET 2003 project, you could
add the database to the setup as a file and place code in the application to
check to see if the database is attached and if not, attach it when you open
the application.
 
Sorry, it's an assembly for asp.net 2.

To make a self-contained assembly i would like to embed (or generate) the
mdb.

:)
 
In that case, when you add a setup project to your main project, simply add
the database mdf as a file. When you open the properties of a project, there
is a prerequisites button on the Configuration Properties screen. In
addition to the bootstrap for NET Framework 2.0, you may also choose to add
SQL Server Express 2005. Clicking this item will load a bootstrap that
checks to see if the user has SQL Server Express loaded. If not, they will
be prompted to download express from the internet and install it. Once this
occurs, your setup will then proceed to attach the datafile (mdf) that you
distribute with your setup file to the Express Server service. You will be
able to immediately access the database from that point forward with your
installed application. It is really that simple.
 
Back
Top