Advertisement
Guest User

Untitled

a guest
Sep 14th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. DataTable infoTable = SQLResults.Tables[0];
  2. foreach (DataRow r in infoTable.Rows)
  3. {
  4.  
  5. foreach (DataColumn c in infoTable.Columns)
  6. {
  7. SQLMsg = SQLMsg + r[c].ToString();
  8. }
  9. }
  10.  
  11. public void DeploySchedServer(string ServerName)
  12. {
  13. string SQLMsg = @"";
  14. string script = @"InsertGenerator2 '" + ServerName + "'";
  15. string SourcesqlConnectionString = @"Asynchronous Processing=true;User=xxxx;Password=xxxxx;Persist Security Info=True;Initial Catalog=SQLMaint;Data Source=devmachine";
  16. string TargetsqlConnectionString = @"Asynchronous Processing=true;User=xxxx;Password=xxxxx;Persist Security Info=True;Initial Catalog=dbadmin;Data Source=" + ServerName;
  17.  
  18. {
  19. SqlConnection SourceConnection = new SqlConnection(SourcesqlConnectionString);
  20. SqlConnection TargetConnection = new SqlConnection(TargetsqlConnectionString);
  21. Server SourceServer = new Server(new ServerConnection(SourceConnection));
  22. Server TargetServer = new Server(new ServerConnection(TargetConnection));
  23. SourceServer.ConnectionContext.ServerMessage += new ServerMessageEventHandler(ConnectionContext_ServerMessage);
  24. TargetServer.ConnectionContext.ServerMessage += new ServerMessageEventHandler(ConnectionContext_ServerMessage);
  25.  
  26.  
  27. try
  28. {
  29. DataSet SQLResults;
  30.  
  31. SQLResults = SourceServer.ConnectionContext.ExecuteWithResults(script);
  32. DataTable infoTable = SQLResults.Tables[0];
  33. foreach (DataRow r in infoTable.Rows)
  34. {
  35.  
  36. foreach (DataColumn c in infoTable.Columns)
  37. {
  38. SQLMsg = SQLMsg + r[c].ToString();
  39. }
  40. }
  41. MessageBox.Show(SQLMsg.ToString());
  42. if (SQLMsg.Length > 0) TargetServer.ConnectionContext.ExecuteNonQuery(SQLMsg);
  43. MessageBox.Show(SQLMsg.Length.ToString());
  44. }
  45.  
  46. catch (Exception ex)
  47. {
  48. MessageBox.Show(ex.Message);
  49. GVTreeView.TreeViewVars.SQLMsg = GVTreeView.TreeViewVars.SQLMsg + ex.Message + "rn";
  50. }
  51. finally
  52. {
  53.  
  54. SourceServer.ConnectionContext.Disconnect();
  55.  
  56.  
  57. }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement