遠端建立資料庫時,通過master(總是存在的乙個資料庫)資料庫進行連線
static bool createdatabase(string strdbsource_, string strusername_, string struserpwd_, string strdbname_, string strpath_)
;strpath_ = strpath_.trimend(strtrim);
// when use in local, can create path auto; otherwise, make sure the path has existed.
//if (!directory.exists(strpath_))
// directory.createdirectory(strpath_);
string strfile = strpath_ + @"/" + strdbname_;
string strsrc = "data source=" + strdbsource_ + ";initial catalog=master;persist security info=true;user id=" +
strusername_ + ";password=" + struserpwd_;
using (sqlconnection conmaster = new sqlconnection(strsrc))
// create the database now;
string strdatabase = "create database " + strdbname_ + " on primary" +
"(" +
@"name=n'" + strdbname_ + @".mdf'," +
@"filename=n'" + strfile + @".mdf'," +
"size=4096kb,maxsize=unlimited,filegrowth=10%)" + // 資料庫檔案至少為3m
"log on" +
"(" +
"name=n'" + strdbname_ + "'," +
@"filename=n'" + strfile + @".ldf'," +
"size=1024kb,maxsize=unlimited,filegrowth=10%)" +
"collate chinese_prc_ci_as"; // 按中文格式排序
sqlcommand cmdcreate = new sqlcommand(strdatabase, conmaster);
cmdcreate.executenonquery();
conmaster.close();
}console.writeline("create ok");
bsuccess = true;
}catch (exception e)
", e.message);
}return bsuccess;
}
遠端使用資料庫
一 問題起源 我在做乙個專案,使用svn存放在伺服器端了。在寫 的時候,需要用到資料庫,而我不想登入到伺服器寫 所以我更改了配置檔案,使連線的是伺服器的資料庫。但是很不幸,當我登入的時候顯示 問題解決 第一步 問題提示是該資料庫拒絕被192.168.1.105的root使用者訪問,所以我先利用 gr...
使用T sql建立資料庫
使用t sql語句建立 myshool 資料庫及刪除資料庫。要求 myshool 資料庫的主資料檔案名為 myshool.mdf,初始大小為3mb,最大為50mb,增長方式為10 日誌檔案的初始大小為1mb,最大為5mb,增長方式為1mb。資料檔案和日誌檔案均存放在d盤根目錄下。create dat...
建立和使用資料庫
建立和使用資料庫 建立資料庫 create database 資料庫名 資料庫名在伺服器中必須是唯一的,並且符合識別符號規則 連線到資料庫 use 資料庫名 刪除資料庫 drop database 資料庫名 整數資料型別 tinyint型 使用tinyint資料型別時,儲存資料的範圍是從0到255....