ASP.Net Website Use
VistaDB works in almost all Asp.net website scenarios because it is medium trust
compliant. This means that VistaDB can run on most shared hosting environments
where other databases cannot. Nothing has to be installed to the GAC for VistaDB
to work.
VistaDB fully supports Connection Pooling to allow websites to share a pool of connections
across multiple pages, this can speed up data access by maintaining open connections
waiting for the next visitor. Websites should still attempt to cache data
whenever possible since the database must be opened in nonexclusive mode for multiple
users to consume data at the same time.
The install on a developers machine includes configuration to use VistaDB in websites,
but to deploy to an actual server you do have to configure the website through the
web.config.
App_Data is a special place
In your connection string the App_Data folder is a very special place. You
don't have to reference it by hand, you can simply use the |DataDirectory| macro
to tell the application to look in the application data directory.
Your connection string would then have something like this:
Data Source='|DataDirectory|mydatabase.vdb4'
And that would load from the App_Data directory on a website.
See the connection
strings page for more information.
Getting a VistaDB License for your Website
Web Sites and Web Applications are slightly different, even though they are both
aspx pages they work differently under the hood.
Both should have a licenses.licx added like any other application (see the help
file for information about the licenses.licx file).
Asp.net Web Applications are compiled on the client, and the license is embedded
automatically.
Aspx Websites are not compiled until they are used. In order to compile the
license you must right click the licenses.licx entry in Visual Studio and tell it
to Build Runtime Licenses. It will then add a new App_Licenses.dll
in the bin folder that must be deployed to the server.
Web.config entries for Entity Framework distribution
To distribute the Entity Framework dll with your website you must include the VistaDB.4.dll
and the VistaDB.Entities.4.dll in your bin folder and put the following entry in
your web.config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="VistaDB.4" />
<add name="VistaDB 4.0" description="VistaDB
4 ADO.NET Provider for .Net 2.0-3.5" invariant="System.Data.VistaDB" type="VistaDB.Provider.VistaDBProviderFactory,
VistaDB.4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=dfc935afe2125461"/>
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="myVDBConnection" connectionString="Data Source='|DataDirectory|\database.vdb4'"
providerName="VistaDB.4" />
</connectionStrings>
</configuration>
The connection string is not required, but putting connection strings in the web.config
is a good idea.
Website has database in use
Your website has the database locked and kept open all the time if it is active,
so how would you upload a new database?
Let's say you have a website and you want to force all the database connections
closed so you can update the database from a local copy. How would you do that without
having access to the server? Microsoft provided a way to do this through taking
the website offline.
Take the Asp.net website Offline
Create a file named App_Offline.htm and upload it to the root of the website. Hit
the homepage and it should show the offline page. Then all database connections
are closed, and you can safely upload a new database.
This is also a good idea for when your website needs to do maintenance on the database
(packing the database is required periodically). You could setup a script on the
server that puts the App_Offline.htm file on the site, make a backup of the database,
pack the database, then delete the file to put the site back online.
Scott Guthrie
has a blog post about taking sites offline.
Asp.net Membership Providers
VistaDB does include Asp.net membership providers as an addon to the core developer
license. Not all of the providers work in medium trust due to a limitation
from Microsoft on how they implemented the providers. We don't recommend
using them in medium trust as a result.
To specify the providers you must include entries to them in your web.config, and
ship the VistaDB.web.4.dll assembly in your bin folder.
<system.web>
<membership defaultProvider="AspNetVistaDBMembershipProvider">
<providers>
<add connectionStringName="ConnectionString"
name="AspNetVistaDBMembershipProvider"
type="VistaDB.Web.VistaDBMembershipProvider,
VistaDB.Web.4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=f5930b27126de908" />
</providers>
</membership>
<profile defaultProvider="AspNetVistaDBProfileProvider" enabled="true">
<providers>
<add connectionStringName="ConnectionString"
name="AspNetVistaDBProfileProvider"
type="VistaDB.Web.VistaDBProfileProvider,
VistaDB.Web.4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=f5930b27126de908" />
</providers>
<properties>
<group name="UserInfo">
<add name="Name" type="System.String" allowAnonymous="true" />
</group>
</properties>
</profile>
<roleManager defaultProvider="AspNetVistaDBRoleProvider" enabled="true">
<providers>
<add connectionStringName="ConnectionString" name="AspNetVistaDBRoleProvider"
type="VistaDB.Web.VistaDBRoleProvider,
VistaDB.Web.4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=f5930b27126de908" />
</providers>
</roleManager>
</system.web>
There is also a special asp membership database included in the addon that includes
all the tables required. aspnetdb.vdb4 is added to your website if you right click
the solution, add new item, and choose VistaDB 4 Asp.Net Database.