private void SwitchDB(DBConnInfo info) { CurrDBConnInfo = info; tSSLName.Text = $"Name : {CurrDBConnInfo.DBTxt}"; tSSLServer.Text = $"Server : {CurrDBConnInfo.Server}"; tSSLDBName.Text = $"DB : {CurrDBConnInfo.DBName}"; db = new DBHelper(SqlClientFactory.Instance, CurrDBConnInfo.GetConnectionString()); DGVObject.DataSource = null; DGVSqlResult.DataSource = null; }
public static string SyncObj(DBConnInfo sour, DBConnInfo trgt, string objName) { try { var type = GetObjType(sour, objName); if (!SqlObjTypeFullName.ContainsKey(type)) { return($"該物件類型{type}尚不支援同步功能"); } var typeName = SqlObjTypeFullName[type]; var sql = $@"if exists(select 1 from sys.sysobjects where name = {{0}}) Drop {typeName} [{objName}]; EXEC dbo.sp_executesql @statement = {{1}}"; var db = new DBHelper(SqlClientFactory.Instance, trgt.GetConnectionString()); db.ExecuteNonQuery(sql, objName, GetDefinition(sour, objName)); return(string.Empty); } catch (Exception ex) { return(ex.Message); } }
public static string GetObjType(DBConnInfo info, string objName) { var db = new DBHelper(SqlClientFactory.Instance, info.GetConnectionString()); return(db.ExecuteScalar <String>("select type from sys.sysobjects where name = {0}", objName).Trim()); }
public static string GetDefinition(DBConnInfo info, string objName) { var db = new DBHelper(SqlClientFactory.Instance, info.GetConnectionString()); return(db.ExecuteScalar <String>("select b.definition from sys.sysobjects a, sys.sql_modules b where a.name = {0} and a.id=b.object_id", objName)); }