Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DataTable infoTable = SQLResults.Tables[0];
- foreach (DataRow r in infoTable.Rows)
- {
- foreach (DataColumn c in infoTable.Columns)
- {
- SQLMsg = SQLMsg + r[c].ToString();
- }
- }
- public void DeploySchedServer(string ServerName)
- {
- string SQLMsg = @"";
- string script = @"InsertGenerator2 '" + ServerName + "'";
- string SourcesqlConnectionString = @"Asynchronous Processing=true;User=xxxx;Password=xxxxx;Persist Security Info=True;Initial Catalog=SQLMaint;Data Source=devmachine";
- string TargetsqlConnectionString = @"Asynchronous Processing=true;User=xxxx;Password=xxxxx;Persist Security Info=True;Initial Catalog=dbadmin;Data Source=" + ServerName;
- {
- SqlConnection SourceConnection = new SqlConnection(SourcesqlConnectionString);
- SqlConnection TargetConnection = new SqlConnection(TargetsqlConnectionString);
- Server SourceServer = new Server(new ServerConnection(SourceConnection));
- Server TargetServer = new Server(new ServerConnection(TargetConnection));
- SourceServer.ConnectionContext.ServerMessage += new ServerMessageEventHandler(ConnectionContext_ServerMessage);
- TargetServer.ConnectionContext.ServerMessage += new ServerMessageEventHandler(ConnectionContext_ServerMessage);
- try
- {
- DataSet SQLResults;
- SQLResults = SourceServer.ConnectionContext.ExecuteWithResults(script);
- DataTable infoTable = SQLResults.Tables[0];
- foreach (DataRow r in infoTable.Rows)
- {
- foreach (DataColumn c in infoTable.Columns)
- {
- SQLMsg = SQLMsg + r[c].ToString();
- }
- }
- MessageBox.Show(SQLMsg.ToString());
- if (SQLMsg.Length > 0) TargetServer.ConnectionContext.ExecuteNonQuery(SQLMsg);
- MessageBox.Show(SQLMsg.Length.ToString());
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- GVTreeView.TreeViewVars.SQLMsg = GVTreeView.TreeViewVars.SQLMsg + ex.Message + "rn";
- }
- finally
- {
- SourceServer.ConnectionContext.Disconnect();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement