public bool CreateDB(string dbName, string path) { //SQLDMO.SQLServer.EnumDirectories(string path); // 创建数据库文件 SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass(); SQLDMO.DBFile dbFile = new SQLDMO.DBFileClass(); try { svr.Connect(ServerName, UserName, Password); svr.EnumDirectories("c:"); dbFile.Name = dbName + "_Data"; dbFile.PhysicalName = Path.Combine(path, dbName + "_Data.MDF"); dbFile.PrimaryFile = true; //dbFile.Size = 2; // 设置初始化大小(MB) //dbFile.FileGrowthType = SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB; // 设置文件增长方式 //dbFile.FileGrowth=1; // 设置增长幅度 // 创建日志文件 SQLDMO._LogFile logFile = new SQLDMO.LogFileClass(); logFile.Name = dbName + "_Log"; logFile.PhysicalName = Path.Combine(path, dbName + "_Log.MDF"); //logFile.Size = 3; //logFile.FileGrowthType=SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB; //logFile.FileGrowth=1; // 创建数据库 SQLDMO.Database db = new SQLDMO.DatabaseClass(); db.Name = dbName; db.FileGroups.Item("PRIMARY").DBFiles.Add(dbFile); db.TransactionLog.LogFiles.Add(logFile); // 建立数据库联接,并添加数据库到服务器 svr.Databases.Add(db); return(true); } catch (Exception err) { //throw (new Exception("!" + err.Message)); ShowError("添加数据库失败!" + err.Message); return(false); } finally { svr.DisConnect(); } }
public bool CreateDB(string dbName, string path) { //SQLDMO.SQLServer.EnumDirectories(string path); // �������ݿ��ļ� SQLDMO.SQLServer svr = new SQLDMO.SQLServerClass(); SQLDMO.DBFile dbFile = new SQLDMO.DBFileClass(); try { svr.Connect(ServerName, UserName, Password); svr.EnumDirectories("c:"); dbFile.Name = dbName + "_Data"; dbFile.PhysicalName = Path.Combine(path, dbName + "_Data.MDF"); dbFile.PrimaryFile = true; //dbFile.Size = 2; // ���ó�ʼ����С(MB) //dbFile.FileGrowthType = SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB; // �����ļ�������ʽ //dbFile.FileGrowth=1; // ������������ // ������־�ļ� SQLDMO._LogFile logFile = new SQLDMO.LogFileClass(); logFile.Name = dbName + "_Log"; logFile.PhysicalName = Path.Combine(path, dbName + "_Log.MDF"); //logFile.Size = 3; //logFile.FileGrowthType=SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB; //logFile.FileGrowth=1; // �������ݿ� SQLDMO.Database db = new SQLDMO.DatabaseClass(); db.Name = dbName; db.FileGroups.Item("PRIMARY").DBFiles.Add(dbFile); db.TransactionLog.LogFiles.Add(logFile); // �������ݿ����ӣ���������ݿ������ svr.Databases.Add(db); return true; } catch (Exception err) { //throw (new Exception("��" + err.Message)); ShowError("������ݿ�ʧ��!" + err.Message); return false; } finally { svr.DisConnect(); } }