Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
DataContext Class
 CreateDatabase Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
DataContext..::.CreateDatabase Method

Creates a database on the server.

Namespace:  System.Data.Linq
Assembly:  System.Data.Linq (in System.Data.Linq.dll)
Visual Basic (Declaration)
Public Sub CreateDatabase
Visual Basic (Usage)
Dim instance As DataContext

instance.CreateDatabase()
C#
public void CreateDatabase()
Visual C++
public:
void CreateDatabase()
JScript
public function CreateDatabase()

The name of the database is derived by using the following algorithm:

  • If a database is identified in the connection string, its name is used.

  • If a DatabaseAttribute attribute is present, its Name property is used as the name of the database.

  • If there is no database tag in the connection string and a strongly typed DataContext is used, a database that has the same name as the DataContext inheriting class is checked.

  • If a weakly typed DataContext is used, an exception is thrown.

  • If the DataContext has been created by using a file name, the database corresponding to that file name is created.

The following code shows how to set up a temporary database and then remove it.

Visual Basic
If Not db.DatabaseExists Then
    db.CreateDatabase()
End If
' ...
db.DeleteDatabase()
C#
if (!db.DatabaseExists())
    db.CreateDatabase();
// …
db.DeleteDatabase();

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker