DataContext.CreateDatabase 方法

定義

在伺服器上建立資料庫。

public:
 void CreateDatabase();
public void CreateDatabase ();
member this.CreateDatabase : unit -> unit
Public Sub CreateDatabase ()

範例

下列程式代碼示範如何設定暫存資料庫,然後加以移除。

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

備註

資料庫名稱是使用下列演算法衍生的:

  1. 如果在 連接字串 中識別資料庫,則會使用其名稱。
  2. 如果屬性 DatabaseAttribute 存在,則會使用其 Name 屬性做為資料庫的名稱。
  3. 如果 連接字串 中沒有資料庫標籤,而且使用強型別DataContext,則會建立與繼承類別同名DataContext的資料庫。
  4. 如果使用弱型別 DataContext ,則會擲回例外狀況。
  5. DataContext如果使用檔名建立 ,則會建立對應至該檔名的資料庫。

適用於

另請參閱