public void CreateAndDropTableTest() { SQLServer objDB = null; Random random = new Random(); try { objDB = TestEnvJudge(); if (objDB != null) { if (objDB.Connect()) { int ret = objDB.ExecuteNonQuery("CREATE TABLE Test_" + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond + " (id int NOT NULL PRIMARY KEY, col_1 nvarchar(10) NULL, col_2 nvarchar(10) NULL, col_3 nvarchar(10) NULL);"); Assert.AreEqual(1, ret); } } } finally { if (objDB.Connect()) { objDB.Disconnect(); } objDB = null; random = null; } }
public void BeginTransTest() { SQLServer objDB = null; try { objDB = TestEnvJudge(); if (objDB != null) { if (objDB.Connect()) { Assert.AreEqual(true, objDB.BeginTrans()); objDB.RollBack(); } } } finally { if (objDB.Connect()) { objDB.Disconnect(); } objDB = null; } }
public void GetTableLockInfoTest() { SQLServer objDB = null; try { objDB = TestEnvJudge(); if (objDB != null) { if (objDB.Connect()) { objDB.BeginTrans(); objDB.ExecuteNonQuery("insert into get_test values (NEXT VALUE FOR get_test_sequence,'','',SYSDATETIME(),SYSDATETIMEOFFSET())"); Assert.AreNotEqual(true, objDB.GetTableLockInfo("get_test")); objDB.RollBack(); } } } finally { if (objDB.Connect()) { objDB.Disconnect(); } objDB = null; } }
public void ConnectTest() { try { if (objDB != null) { Assert.AreEqual(true, objDB.Connect()); } } finally { objDB.Disconnect(); } }
/// <summary> /// 备份数据库 /// </summary> /// <param name="serverName">数据实例名</param> /// <param name="userName">用户</param> /// <param name="password">密码</param> /// <param name="databaseName">库名</param> /// <param name="path">备份路径</param> public static void CompressDatabase(string serverName,string userName,string password,string databaseName,string path) { Backup oBackup = new Backup(); SQLServer oSQLServer = new SQLServer(); try { oSQLServer.LoginSecure = false; oSQLServer.Connect(serverName, userName, password); oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; oBackup.Database = databaseName; oBackup.Files = path; oBackup.BackupSetName = databaseName; oBackup.BackupSetDescription = string.Format("{0} {1}", databaseName, DateTime.Now); oBackup.Initialize = true; oBackup.SQLBackup(oSQLServer); } catch { throw; } finally { oSQLServer.DisConnect(); } }
public static void DbRestore(string string_0, string string_1, string string_2, string string_3, string string_4) { Restore restoreClass = new Restore(); SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.LoginSecure = false; sQLServerClass.Connect(string_0.Trim(), string_1.Trim(), string_2.Trim()); restoreClass.Action = 0; restoreClass.Database = string_3.Trim(); restoreClass.Files = string_4; restoreClass.FileNumber = 1; restoreClass.ReplaceDatabase = true; restoreClass.SQLRestore(sQLServerClass); } catch { throw; } } finally { sQLServerClass.DisConnect(); } }
/// <summary> /// 还原数据库 /// </summary> /// <param name="serverName">数据实例名</param> /// <param name="userName">用户</param> /// <param name="password">密码</param> /// <param name="databaseName">库名</param> /// <param name="path">文件路径</param> public static void RestoreDatabase(string serverName, string userName, string password, string databaseName, string path) { SQLDMO.Restore oRestore = new SQLDMO.Restore(); SQLServer oSQLServer = new SQLServer(); try { oSQLServer.LoginSecure = false; oSQLServer.Connect(serverName, userName, password); oRestore.Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database; oRestore.Database = databaseName; oRestore.Files = path; oRestore.FileNumber = path.Split(',').Count(); oRestore.BackupSetName = databaseName; oRestore.ReplaceDatabase = true; oRestore.SQLRestore(oSQLServer); } catch { throw; } finally { oSQLServer.DisConnect(); } }
public static bool GetMachineSQL(string string_0, string string_1, string string_2) { SQLServer sQLServerClass = new SQLServer(); bool flag = false; sQLServerClass.LoginSecure = false; try { sQLServerClass.Connect(string_0, string_1, string_2); flag = true; } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode == -2147221504) { MessageBox.Show("服务器没有启动或不存在"); } if (cOMException.ErrorCode == -2147203048) { MessageBox.Show(string.Concat("用户名'", string_1, "'登录失败")); } if (cOMException.ErrorCode == -2147204362) { MessageBox.Show("服务器暂停,不允许进行新的连接"); } flag = false; } return(flag); }
/// <summary> /// 备份数据库 /// </summary> /// <param name="serverName">数据实例名</param> /// <param name="userName">用户</param> /// <param name="password">密码</param> /// <param name="databaseName">库名</param> /// <param name="path">备份路径</param> public static void CompressDatabase(string serverName, string userName, string password, string databaseName, string path) { Backup oBackup = new Backup(); SQLServer oSQLServer = new SQLServer(); try { oSQLServer.LoginSecure = false; oSQLServer.Connect(serverName, userName, password); oBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; oBackup.Database = databaseName; oBackup.Files = path; oBackup.BackupSetName = databaseName; oBackup.BackupSetDescription = string.Format("{0} {1}", databaseName, DateTime.Now); oBackup.Initialize = true; oBackup.SQLBackup(oSQLServer); } catch { throw; } finally { oSQLServer.DisConnect(); } }
public static void DbBackup(string string_0, string string_1, string string_2, string string_3, string string_4, string string_5, string string_6) { Backup backupClass = new Backup(); SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.LoginSecure = false; sQLServerClass.Connect(string_0.Trim(), string_1.Trim(), string_2.Trim()); backupClass.Action = 0; backupClass.Database = string_3.Trim(); backupClass.Files = string_4; backupClass.BackupSetName = string_5; backupClass.BackupSetDescription = string_6; backupClass.Initialize = true; backupClass.SQLBackup(sQLServerClass); } catch { throw; } } finally { sQLServerClass.DisConnect(); } }
private void remplirComboBase(ComboBox combo, string server, string user, string pass) { var fServer = new SQLServer(); try { combo.Items.Clear(); fServer.Connect(server, user, pass); for (int i = 0; i < fServer.Databases.Count; i++) { combo.Items.Add(fServer.Databases.Item(i + 1).Name); } // Back to normal Cursor.Current = Cursors.Default; } catch (Exception e) { // Back to normal Cursor.Current = Cursors.Default; MessageBox.Show(e.Message + $@" Serveur: {server} Utilisateur: {user} Mot de Passe: {pass}", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { // Back to normal Cursor.Current = Cursors.Default; } }
static void Main(string[] args) { var ss = new SQLServer(); var ok = ss.Connect("localhost", "sqlexpress", "EdDb"); var students = ss.ExcecuteQuery("SELECT * From Student;"); ss.Disconnect(); }
static void Main(string[] args) { string word = "fast"; string character = Convert.ToString(word[0]); var ss = new SQLServer(); var ok = ss.Connect("localhost", "sqlexpress", "EdDb"); var students = ss.ExecuteQuery("SELECT * From Student;"); ss.Disconnect(); }
private void method_1(string string_0, string string_1, string string_2) { SQLServer sQLServerClass = new SQLServer(); Database databaseClass = new Database(); sQLServerClass.LoginSecure = false; int count = 0; this.SQLSDE.Items.Clear(); try { sQLServerClass.Connect(string_0, string_1, string_2); count = sQLServerClass.Databases.Count; } catch (Exception exception) { COMException cOMException = exception as COMException; if (cOMException.ErrorCode == -2147221504) { MessageBox.Show("服务器没有启动或不存在"); } if (cOMException.ErrorCode == -2147203048) { MessageBox.Show(string.Concat("用户名'", string_1, "'登录失败")); } if (cOMException.ErrorCode == -2147204362) { MessageBox.Show("服务器暂停,不允许进行新的连接"); } return; } try { try { for (int i = 1; i < count + 1; i++) { string name = ""; databaseClass = (Database)sQLServerClass.Databases.ItemByID(i); name = databaseClass.Name; this.SQLSDE.Items.Add(name); } } catch (Exception exception1) { } } finally { sQLServerClass.DisConnect(); } }
public bool BackUPDB(string string_3, string string_4, System.Windows.Forms.ProgressBar progressBar_1) { this.progressBar_0 = progressBar_1; SQLServer sQLServer = new SQLServer(); Database database = new Database(); bool result; try { sQLServer.Connect(this.ServerName, this.UserName, this.Password); int i = 1; while (i <= sQLServer.Databases.Count) { if (!(sQLServer.Databases.ItemByID(i).Name.Trim() == string_3)) { i++; } else { database = (Database)sQLServer.Databases.ItemByID(i); IL_7B: if (!database.Isdb_owner) { System.Windows.Forms.MessageBox.Show("没有足够的操作权限"); result = false; return(result); } Backup backup = new Backup(); backup.Action = 0; backup.Initialize = true; BackupSink_PercentCompleteEventHandler backupSink_PercentCompleteEventHandler = new BackupSink_PercentCompleteEventHandler(this.Step); backup.PercentComplete += (backupSink_PercentCompleteEventHandler); backup.Files = (string_4); backup.Database = (string_3); backup.SQLBackup(sQLServer); result = true; return(result); } } } catch (System.Exception ex) { throw new System.Exception("备份数据库失败" + ex.Message); } finally { sQLServer.DisConnect(); } return(false); }
public void GetDataTest() { SQLServer objDB = null; try { objDB = TestEnvJudge(); if (objDB != null) { if (objDB.Connect()) { DataTable dataTable = objDB.ExecuteReader("SELECT * FROM get_test"); } } } finally { if (objDB.Connect()) { objDB.Disconnect(); } objDB = null; } }
protected void btnDBRecovery_Click(object sender, EventArgs e) { Restore dbRestore = new Restore(); SQLServer sqlServer = new SQLServer(); sqlServer.LoginSecure = false; sqlServer.Connect(".", "sa", ""); dbRestore.Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database; dbRestore.Database = "Yuchen"; dbRestore.Files = @"C:\BackupOfYuchen\BackupOfYuchen.bak";//和上面的路径保持一致 dbRestore.FileNumber = 1; dbRestore.ReplaceDatabase = true; dbRestore.SQLRestore(sqlServer); sqlServer.DisConnect(); }
public ArrayList ListAllTables() { //create a new ArrayList ArrayList TableList = new ArrayList(); //try //{ //Retrieve the Database specified //DBase = (SQLDMO.Database)Server.Databases.Item(db_name, null); var fServer = new SQLServer(); fServer.Connect(SunriseServer(), sunriseUser(), sunrisePass()); //Loop through all the tables on the database //NOTE: we arent showing system tables table = fServer.Databases.Item(SunriseBD(), null).Tables; foreach (Table tbl in table) { //Make sure the table doesnt //begin with "sys" if (tbl.Name.Length <= 3) { if (!TableList.Contains(tbl.Name)) { //It doesnt so add it TableList.Add(tbl.Name); } } else if (!(tbl.Name.Substring(0, 3) == "sys")) { //Check to see if the table already //exists in our ArrayList if (!TableList.Contains(tbl.Owner + tbl.Name)) { //It doesnt so add it TableList.Add(tbl.Name); } } } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} //return the ArrayList return(TableList); }
public void ConnectTest() { SQLServer objDB = null; try { objDB = TestEnvJudge(); if (objDB != null) { Assert.AreEqual(true, objDB.Connect()); } } finally { objDB.Disconnect(); objDB = null; } }
/// <summary> /// /// </summary> /// <returns></returns> private bool connectDB() { bool b = false; try { disconnectDB(); sqlSrv.Connect(this.cboServer.Text.ToString(), this.txtUserNameDB.Text.Trim(), this.txtPass.Text.Trim()); b = true; return(b); } catch (Exception e) { MessageBox.Show("Can not connect to database!", "Connect Database", MessageBoxButtons.OK, MessageBoxIcon.Information); return(b); } }
public static bool DbRestoreEx(string string_0, string string_1, string string_2, string string_3, string string_4) { bool flag = false; string columnString = ""; Restore restoreClass = new Restore(); SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.LoginSecure = false; sQLServerClass.Connect(string_0.Trim(), string_1.Trim(), string_2.Trim()); restoreClass.Action = 0; restoreClass.Database = string_3.Trim(); restoreClass.Files = string_4; restoreClass.FileNumber = 1; columnString = restoreClass.ReadFileList(sQLServerClass).GetColumnString(1, 2); columnString = columnString.Substring(0, columnString.LastIndexOf('\\')); if (!Directory.Exists(columnString)) { Directory.CreateDirectory(columnString); } restoreClass.ReplaceDatabase = true; restoreClass.SQLRestore(sQLServerClass); flag = true; } catch (Exception exception) { exception.ToString(); MessageBox.Show("请删除与要恢复的数据库同名的数据文件"); } } finally { sQLServerClass.DisConnect(); } return(flag); }
protected void btnDBBackup_Click(object sender, EventArgs e) { Backup dbBackup = new Backup(); SQLServer sqlServer = new SQLServer(); sqlServer.LoginSecure = false; sqlServer.Connect(".", "sa", ""); dbBackup.Action = SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database; dbBackup.Database = "Yuchen"; dbBackup.Files = @"C:\BackupOfYuchen\BackupOfYuchen.bak";//这些路径不会自己创建,不能有空格 dbBackup.BackupSetName = "BackupOfYuchen"; dbBackup.BackupSetDescription = "备份数据库Yuchen"; dbBackup.Initialize = true; dbBackup.SQLBackup(sqlServer); sqlServer.DisConnect(); Response.Write("<script language=\"javascript\">alert('已经将数据库备份到C:\\\\BackupOfYuchen')</script>"); }
private bool Open() { try { string strIP = GetConfigValue("Server").ToString(); string uid = GetConfigValue("uid").ToString(); string pwd = GetConfigValue("pwd").ToString(); if (svr == null) { svr = new SQLServerClass(); // svr.Connect(".", "sa", "sa"); svr.Connect(strIP, uid, pwd); } else { svr.Close(); svr = new SQLServerClass(); // svr.Connect(".", "sa", "sa"); svr.Connect(strIP, uid, pwd); } } catch (System.Runtime.InteropServices.COMException ce) { if (ce.ErrorCode == -2147203048) { ErrorMessage(2023048, ce.StackTrace, "[DataBaseManage:Open]", ce.Message); return(false); } //不存在或访问被拒绝 if (ce.ErrorCode == -2147221504) { ErrorMessage(2021504, ce.StackTrace, "[DataBaseManage:Open]", ce.Message); return(false); } } return(true); }
public ArrayList ListStoredProcedures() { ArrayList SPList = new ArrayList(); var fServer = new SQLServer(); fServer.Connect(server(), user(), pass()); try { Liste_procedure = fServer.Databases.Item(bd(), null).StoredProcedures; foreach (StoredProcedure sp in Liste_procedure) { if (!SPList.Contains(sp.Owner + "." + sp.Name)) { SPList.Add(sp.Owner + "." + sp.Name); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(SPList); }
public ArrayList GetDbList(string string_3, string string_4, string string_5) { this.ServerName = string_3; this.UserName = string_4; this.Password = string_5; ArrayList arrayLists = new ArrayList(); SQLDMO.Application applicationClass = new Application(); SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.Connect(this.ServerName, this.UserName, this.Password); foreach (Database databasis in sQLServerClass.Databases) { if (databasis.Name == null) { continue; } arrayLists.Add(databasis.Name); } } catch (Exception exception) { throw new Exception(string.Concat("连接数据库出错:", exception.Message)); } } finally { sQLServerClass.DisConnect(); applicationClass.Quit(); } return(arrayLists); }
public bool RestoreDB(string string_3, string string_4, string string_5, ProgressBar progressBar_1) { int i; bool flag; this.progressBar_0 = progressBar_1; string columnString = ""; string str = ""; string str1 = ""; string str2 = ""; SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.Connect(this.ServerName, this.UserName, this.Password); QueryResults queryResult = sQLServerClass.EnumProcesses(-1); int num = -1; int num1 = -1; for (i = 1; i <= queryResult.Columns; i++) { string columnName = queryResult.ColumnName[i]; if (columnName.ToUpper().Trim() == "SPID") { num = i; } else if (columnName.ToUpper().Trim() == "DBNAME") { num1 = i; } if ((num == -1 ? false : num1 != -1)) { break; } } for (i = 1; i <= queryResult.Rows; i++) { int columnLong = queryResult.GetColumnLong(i, num); if (queryResult.GetColumnString(i, num1).ToUpper() == string_3.ToUpper()) { sQLServerClass.KillProcess(columnLong); } } Restore restoreClass = new Restore() { Action = SQLDMO_RESTORE_TYPE.SQLDMORestore_Database }; restoreClass.PercentComplete += new RestoreSink_PercentCompleteEventHandler(this.Step); restoreClass.Files = string_4; restoreClass.Database = string_3; restoreClass.RelocateFiles = "[SuperOA],[D:\\aaaa.mdf]"; columnString = restoreClass.ReadFileList(sQLServerClass).GetColumnString(1, 1); str = restoreClass.ReadFileList(sQLServerClass).GetColumnString(2, 1); str1 = string.Concat(string_5, columnString, ".mdf"); str2 = string.Concat(string_5, str, ".ldf"); string[] strArrays = new string[] { "[", columnString, "],[", str1, "],[", str, "],[", str2, "]" }; restoreClass.RelocateFiles = string.Concat(strArrays); restoreClass.ReplaceDatabase = true; restoreClass.SQLRestore(sQLServerClass); flag = true; } catch (Exception exception) { exception.Message.ToString(); MessageBox.Show("恢复数据库失败,请关闭所有和该数据库连接的程序!"); flag = false; } } finally { sQLServerClass.DisConnect(); } return(flag); }
public static bool GetMachineSQL(string string_0, string string_1, string string_2, string string_3) { bool flag; SQLServer sQLServerClass = new SQLServer(); Database databaseClass = new Database(); bool flag1 = false; bool flag2 = false; sQLServerClass.LoginSecure = false; int count = 0; try { sQLServerClass.Connect(string_0, string_2, string_3); count = sQLServerClass.Databases.Count; } catch (COMException cOMException1) { COMException cOMException = cOMException1; if (cOMException.ErrorCode == -2147221504) { MessageBox.Show("服务器没有启动或不存在"); } if (cOMException.ErrorCode == -2147203048) { MessageBox.Show(string.Concat("用户名'", string_2, "'登录失败")); } if (cOMException.ErrorCode == -2147204362) { MessageBox.Show("服务器暂停,不允许进行新的连接"); } flag = flag2; return(flag); } try { try { int num = 1; while (true) { if (num < count + 1) { string str = ""; databaseClass = (Database)sQLServerClass.Databases.ItemByID(num); str = databaseClass.Name.Trim(); if (string_1.Trim().ToUpper() == str.ToUpper()) { flag1 = true; break; } else { num++; } } else { break; } } if (!flag1) { MessageBox.Show("目标服务器上不存在该数据库"); } } catch (Exception exception) { MessageBox.Show(exception.Message.ToString()); } } finally { sQLServerClass.DisConnect(); } flag = flag2; return(flag); }
public static bool DbBackupEx(string string_0, string string_1, string string_2, string string_3, string string_4, string string_5, string string_6) { bool flag; bool flag1 = false; Backup backupClass = new Backup(); SQLServer sQLServerClass = new SQLServer(); try { if (!File.Exists(string_4)) { FileStream fileStream = File.Create(string_4); try { } finally { if (fileStream != null) { ((IDisposable)fileStream).Dispose(); } } } } catch (Exception exception) { MessageBox.Show(exception.ToString()); flag = false; return(flag); } if ((string_5 == null ? true : string_5 == "")) { string_5 = string.Concat("你现在进行了数据库", string_3.Trim(), "的备份设置"); } if ((string_6 == null ? true : string_6 == "")) { string_6 = string.Concat("你现在备份的数据库为", string_3.Trim()); } try { try { sQLServerClass.LoginSecure = false; sQLServerClass.Connect(string_0.Trim(), string_1.Trim(), string_2.Trim()); backupClass.Action = 0; backupClass.Database = string_3.Trim(); backupClass.Files = string_4; backupClass.BackupSetName = string_5; backupClass.BackupSetDescription = string_6; backupClass.Initialize = true; backupClass.SQLBackup(sQLServerClass); flag1 = true; } catch (Exception exception1) { MessageBox.Show(exception1.Message.ToString()); } } finally { sQLServerClass.DisConnect(); } flag = flag1; return(flag); }
private bool Open() { try { string strIP = GetConfigValue("Server").ToString(); string uid = GetConfigValue("uid").ToString(); string pwd = GetConfigValue("pwd").ToString(); if (svr == null) { svr = new SQLServerClass(); // svr.Connect(".", "sa", "sa"); svr.Connect(strIP, uid, pwd); } else { svr.Close(); svr = new SQLServerClass(); // svr.Connect(".", "sa", "sa"); svr.Connect(strIP, uid, pwd); } } catch (System.Runtime.InteropServices.COMException ce) { if (ce.ErrorCode == -2147203048) { ErrorMessage(2023048, ce.StackTrace, "[DataBaseManage:Open]", ce.Message); return false; } //不存在或访问被拒绝 if (ce.ErrorCode == -2147221504) { ErrorMessage(2021504, ce.StackTrace, "[DataBaseManage:Open]", ce.Message); return false; } } return true; }
//procedure SQLDMOButtonOnClick(Sender: TObject); //var // SQLServer, Database, DBFile, LogFile: Variant; // IDColumn, NameColumn, Table: Variant; //begin // if MsgBox('Setup will now connect to Microsoft SQL Server ''' + SQLServerName + ''' via a trusted connection and create a database. Do you want to continue?', mbInformation, mb_YesNo) = idNo then // Exit; // { Create the main SQLDMO COM Automation object } // try // SQLServer := CreateOleObject('SQLDMO.SQLServer'); // except // RaiseException('Please install Microsoft SQL server connectivity tools first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)'); // end; // { Connect to the Microsoft SQL Server } // SQLServer.LoginSecure := True; // SQLServer.Connect(SQLServerName); // MsgBox('Connected to Microsoft SQL Server ''' + SQLServerName + '''.', mbInformation, mb_Ok); // { Setup a database } // Database := CreateOleObject('SQLDMO.Database'); // Database.Name := 'Inno Setup'; // DBFile := CreateOleObject('SQLDMO.DBFile'); // DBFile.Name := 'ISData1'; // DBFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.mdf'; // DBFile.PrimaryFile := True; // DBFile.FileGrowthType := SQLDMOGrowth_MB; // DBFile.FileGrowth := 1; // Database.FileGroups.Item('PRIMARY').DBFiles.Add(DBFile); // LogFile := CreateOleObject('SQLDMO.LogFile'); // LogFile.Name := 'ISLog1'; // LogFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.ldf'; // Database.TransactionLog.LogFiles.Add(LogFile); // { Add the database } // SQLServer.Databases.Add(Database); // MsgBox('Added database ''' + Database.Name + '''.', mbInformation, mb_Ok); // { Setup some columns } // IDColumn := CreateOleObject('SQLDMO.Column'); // IDColumn.Name := 'id'; // IDColumn.Datatype := 'int'; // IDColumn.Identity := True; // IDColumn.IdentityIncrement := 1; // IDColumn.IdentitySeed := 1; // IDColumn.AllowNulls := False; // NameColumn := CreateOleObject('SQLDMO.Column'); // NameColumn.Name := 'name'; // NameColumn.Datatype := 'varchar'; // NameColumn.Length := '64'; // NameColumn.AllowNulls := False; // { Setup a table } // Table := CreateOleObject('SQLDMO.Table'); // Table.Name := 'authors'; // Table.FileGroup := 'PRIMARY'; // { Add the columns and the table } // Table.Columns.Add(IDColumn); // Table.Columns.Add(NameColumn); // Database.Tables.Add(Table); // MsgBox('Added table ''' + Table.Name + '''.', mbInformation, mb_Ok); //end; private void SQLDMOButtonOnClick(TObject Sender) { if (MsgBox("Setup will now connect to Microsoft SQL Server \"" + SQLServerName + "\" via a trusted connection and create a database. Do you want to continue?", TMsgBoxType.Information, MB.YesNo) == MsgBoxResult.No) { return; } // Create the main SQLDMO COM Automation object dynamic SQLServer; try { SQLServer = CreateOleObject("SQLDMO.SQLServer"); } catch { throw new Exception("Please install Microsoft SQL server connectivity tools first\r\r(Error \"" + GetExceptionMessage() + "\" occurred"); } // Connect to the Microsoft SQL Server SQLServer.LoginSecure = true; SQLServer.Connect(SQLServerName); MsgBox("Connected to Microsoft SQL Server \"" + SQLServerName + "\".", TMsgBoxType.Information, MB.Ok); // Setup a database var Database = CreateOleObject("SQLDMO.Database"); Database.Name = "Inno Setup"; var DBFile = CreateOleObject("SQLDMO.DBFile"); DBFile.Name = "ISData1"; DBFile.PhysicalName = "c:\\program files\\microsoft sql server\\mssql\\data\\IS.mdf"; DBFile.PrimaryFile = true; DBFile.FileGrowthType = SQLDMOGrowth_MB; DBFile.FileGrowth = 1; Database.FileGroups.Item("PRIMARY").DBFiles.Add(DBFile); var LogFile = CreateOleObject("SQLDMO.LogFile"); LogFile.Name = "ISLog1"; LogFile.PhysicalName = "c:\\program files\\microsoft sql server\\mssql\\data\\IS.ldf"; Database.TransactionLog.LogFiles.Add(LogFile); // Add the database SQLServer.Databases.Add(Database); MsgBox("Added database '" + Database.Name + "'.", TMsgBoxType.Information, MB.Ok); // Setup some columns var IDColumn = CreateOleObject("SQLDMO.Column"); IDColumn.Name = "id"; IDColumn.Datatype = "int"; IDColumn.Identity = true; IDColumn.IdentityIncrement = 1; IDColumn.IdentitySeed = 1; IDColumn.AllowNulls = false; var NameColumn = CreateOleObject("SQLDMO.Column"); NameColumn.Name = "name"; NameColumn.Datatype = "varchar"; NameColumn.Length = "64"; NameColumn.AllowNulls = false; // Setup a table var Table = CreateOleObject("SQLDMO.Table"); Table.Name = "authors"; Table.FileGroup = "PRIMARY"; // Add the columns and the table Table.Columns.Add(IDColumn); Table.Columns.Add(NameColumn); Database.Tables.Add(Table); MsgBox("Added table '" + Table.Name + "'.", TMsgBoxType.Information, MB.Ok); }