本文整理汇总了C#中ServerConnection.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# ServerConnection.Connect方法的具体用法?C# ServerConnection.Connect怎么用?C# ServerConnection.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServerConnection
的用法示例。
在下文中一共展示了ServerConnection.Connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btnComparison_Click
protected void btnComparison_Click(object sender, EventArgs e)
{
try
{
ServerConnection conTar = new ServerConnection(this.txtTarServer.Text,
this.txtTarUid.Text,
this.txtTarPwd.Text);
conTar.Connect();
Session.Add("TarServerName", this.txtTarServer.Text);
Session.Add("TarUName", this.txtTarUid.Text);
Session.Add("TarUpwd", this.txtTarPwd.Text);
ServerConnection conSour = new ServerConnection(this.txgSourName.Text,
this.txtSourUid.Text,
this.txtSourPwd.Text);
conSour.Connect();
Session.Add("SourServerName", this.txgSourName.Text);
Session.Add("SourUName", this.txtSourUid.Text);
Session.Add("SourUpwd", this.txtSourPwd.Text);
Response.Redirect("DatabasesPage.aspx");
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
}
示例2: GetJob
public Job GetJob()
{
ServerConnection connection = new ServerConnection("mi001-ws00071", "SA", "Oberon");
connection.Connect();
Server jobserver = new Server(connection);
return jobserver.JobServer.Jobs["PVX"];
}
示例3: ExecuteSqlScript
private static bool ExecuteSqlScript(string connectionString, string databaseName, string script)
{
bool scriptSucceeded = false;
var connection = new ServerConnection();
connection.ConnectionString = connectionString;
connection.StatementTimeout = 3600;
connection.Connect();
Server sqlServer = new Server(connection);
Database dbTarget = sqlServer.Databases[databaseName];
if (dbTarget != null)
{
connection.BeginTransaction();
try
{
dbTarget.ExecuteNonQuery(script);
connection.CommitTransaction();
scriptSucceeded = true;
}
catch (Exception ex)
{
connection.RollBackTransaction();
throw new Exception("Failed to execute script", ex);
}
finally
{
connection.Disconnect();
}
}
return scriptSucceeded;
}
示例4: GetServer
public Server GetServer(ServerConnection connection)
{
if (connection != null)
{
var server = new Server(connection);
connection.Connect();
return server;
}
return null;
}
示例5: TestServerConnection
private static bool TestServerConnection(ServerConnection sc, out string error)
{
try
{
sc.ConnectTimeout = 20;//20 seconds
sc.Connect();
if(sc.ServerVersion.Major < 9)
{
error = "Unable to profile SQL Server with version less than 9.0 (SQL Server 2005)";
return false;
}
error = string.Empty;
return true;
}
catch (Exception exc)
{
error = exc.Message;
return false;
}
}
示例6: EjecutarScriptSQLConSmo
private bool EjecutarScriptSQLConSmo(string m_nombreServidor, string m_login, string m_password, string nombreNuevaBase)
{
bool flag;
try
{
if (this.script == "")
{
return false;
}
ServerConnection serverConnection = new ServerConnection
{
ServerInstance = m_nombreServidor
};
if (m_login != "")
{
serverConnection.LoginSecure = false;
serverConnection.Login = m_login;
serverConnection.Password = m_password;
}
serverConnection.Connect();
Server server = new Server(serverConnection);
serverConnection.ExecuteNonQuery(this.script);
flag = true;
}
catch (ConnectionFailureException)
{
MessageBox.Show("Conexi\x00f3n al servidor fallada.");
flag = false;
}
catch (SmoException exception)
{
throw exception;
}
catch (Exception exception2)
{
throw exception2;
}
return flag;
}
示例7: Connect
public bool Connect()
{
//Cursor = Cursors.WaitCursor;
//connect on the server
sc = new ServerConnection(new ConnectionProperties
{
ServerHostName = this.HostName,
OpenTimeout = new TimeSpan(0, 0, 10),
ServerCertificateValidationMode =CertificateValidationMode.None
});
try
{
sc.Connect();
}
catch (Exception ex)
{
Console.WriteLine("Cannot connect to Historian Server:" + this.HostName);
Console.WriteLine(ex.ToString());
throw;
}
return sc.IsConnected();
//Cursor = Cursors.Default;
}
示例8: WebSyncOptions_Load
private void WebSyncOptions_Load(object sender, EventArgs e)
{
passwordTextBox.Text = string.Empty;
try
{
subscriberConn = new ServerConnection(subscriberServer);
subscriberConn.Connect();
mergePullSub = new MergePullSubscription(subscriptionDatabase,
publisherServer, publicationDatabase, publicationName,
subscriberConn);
mergePullSub.Load();
if (mergePullSub.UseWebSynchronization)
{
enableWebSyncChkBox.Checked = true;
useWebSync = true;
}
if (string.IsNullOrEmpty(mergePullSub.InternetUrl) == false)
{
webSyncUrlTexBox.Text = mergePullSub.InternetUrl;
}
else
{
webSyncUrlTexBox.Text = webSynchronizationUrl;
}
if (string.IsNullOrEmpty(mergePullSub.InternetLogin) == false)
{
userNameTextBox.Text = mergePullSub.InternetLogin;
}
else
{
if (Environment.UserDomainName.Length != 0)
{
userNameTextBox.Text = Environment.UserDomainName
+ @"\" + Environment.UserName;
}
else
{
userNameTextBox.Text = Environment.UserName;
}
}
if (mergePullSub.UseWebSynchronization == false)
{
userNameTextBox.Enabled = false;
passwordTextBox.Enabled = false;
}
}
catch (Exception ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
this.Close();
}
}
示例9: DoWork
private void DoWork()
{
TcpListener listener = null;
try
{
listener = new TcpListener(IPAddress.Any, Port);
listener.Start();
while (!ShutdownTokenSource.Token.IsCancellationRequested)
{
if (listener.Pending())
{
try
{
TcpClient client = listener.AcceptTcpClient();
ServerConnection serverConnection = new ServerConnection(this, client);
serverConnection.Connect();
}
catch (Exception exc)
{
LogError(exc);
}
}
Thread.Sleep(10);
}
}
catch (Exception exc)
{
LogError(exc);
}
finally
{
if (listener != null)
listener.Stop();
Worker = null;
}
}
示例10: GetConnection
ServerConnection GetConnection()
{
string serverName = serverTextBox.Text.Trim();
if (String.IsNullOrEmpty(serverName))
{
MessageBox.Show("You must first specify the name of a server");
serverTextBox.Focus();
return null;
}
Cursor currentCursor = Cursor.Current;
try
{
Cursor.Current = Cursors.WaitCursor;
ServerConnection result = new ServerConnection();
result.ServerInstance = serverName;
result.ConnectTimeout = 15;
result.LoginSecure = windowsAuthenticationRadioButton.Checked;
if (!result.LoginSecure)
{
result.Login = userNameTextBox.Text;
result.Password = passwordTextBox.Text;
}
result.Connect();
return result;
}
catch (Exception e)
{
this.Cursor = currentCursor;
MessageBox.Show(e.Message);
}
finally
{
this.Cursor = currentCursor;
}
return null;
}
示例11: SynchronizeSubscriptionUploadOnly
public void SynchronizeSubscriptionUploadOnly()
{
MergeSynchronizationAgent syncAgent;
try
{
// Make the connection and get the subscription properties.
subscriberConn = new ServerConnection(subscriberServer);
subscriberConn.Connect();
}
catch (Microsoft.SqlServer.Replication.ConnectionFailureException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(
Properties.Resources.ExceptionCannotConnectLocal,
Properties.Resources.ExceptionSqlServerError,
ExceptionMessageBoxButtons.OK);
emb.InnerException = ex;
emb.Show(this);
// Shutdown the application because we can't continue.
Application.Exit();
}
mergePullSub = new MergePullSubscription();
// Set the properties needed to get the subscription.
mergePullSub.ConnectionContext = subscriberConn;
mergePullSub.PublicationName = publicationName;
mergePullSub.PublisherName = publisherServer;
mergePullSub.PublicationDBName = publicationDatabase;
mergePullSub.DatabaseName = subscriptionDatabase;
// Load the properties of the existing subscription.
if (!mergePullSub.LoadProperties())
{
throw new ApplicationException(
Properties.Resources.ExceptionProblemLocalData
+ Environment.NewLine
+ Properties.Resources.ExceptionContactTechSupport);
}
// Get the Merge Agent for synchronous execution.
syncAgent = mergePullSub.SynchronizationAgent;
// Specify an upload-only exchange type.
syncAgent.ExchangeType = MergeExchangeType.Upload;
// Generate a troubleshooting log file.
syncAgent.Output = outputLogFile;
syncAgent.OutputVerboseLevel = outputLevel;
// Define the event handler.
syncAgent.Status += new AgentCore.StatusEventHandler(Sync_Status);
// Start the Merge Agent Job.
try
{
syncAgent.Synchronize();
}
catch (Exception ex)
{
statusProgressBar.Value = 0;
throw new ApplicationException(
Properties.Resources.ExceptionMergeAgentFailedSync,
ex);
}
finally
{
closeButton.Enabled = true;
subscriberConn.Disconnect();
}
}
示例12: GetServerConnection
internal ServerConnection GetServerConnection(string databaseName)
{
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.DataSource = this.serverName;
if (this.trustServerCertificate)
{
csb.TrustServerCertificate = true;
}
if (!string.IsNullOrEmpty(databaseName))
{
csb.InitialCatalog = databaseName;
}
if (this.useSSL)
{
csb.Encrypt = true;
}
else
{
csb.Encrypt = false;
}
if (this.useWindowsAuth == false)
{
if (userName == null)
{
throw new ArgumentException("User name must be specified unless Windows Authentication (-E) is specified.");
}
if (password == null)
{
throw new InvalidArgumentException("User password must be specified unless Windows Authentication (-E) is specified.");
}
csb.IntegratedSecurity = false;
csb.UserID = this.userName;
csb.Password = this.password;
}
else
{
csb.IntegratedSecurity = true;
}
csb.ConnectTimeout = 60;
csb.MinPoolSize = 5;
csb.MaxPoolSize = 50; // According to Azure team there is NO max limit on connections. It all comes down to CPU and IO usage. They said setting this to 100 would be fine.
csb.Pooling = true;
// If we think we are talking to Azure we should turn on encryption if the user didn't set it
if ( (this.azureEdition != AzureEdition.Default || this.azureSize != -1) && this.useSSL == false )
{
Console.WriteLine("Turning on Encryption for SQL Azure");
csb.Encrypt = true;
}
ServerConnection connection = new ServerConnection();
connection.ConnectionString = csb.ToString();
connection.StatementTimeout = 60 * 60 * 24;
Console.WriteLine("Connecting to {0}...", this.serverName);
connection.Connect();
Console.WriteLine("Connection Open.");
return connection;
}
示例13: LoadSubscriptionProperties
private void LoadSubscriptionProperties(string subscriber)
{
int subTextLength = 40;
string subId;
try
{
// Get default values from the current SQL Server
ServerConnection serverConnection = new ServerConnection(subscriber);
serverConnection.Connect();
ReplicationServer replServer = new ReplicationServer(serverConnection);
// Get the subscriptions on this Subscriber.
availableSubscriptions =
replServer.EnumSubscriberSubscriptions(null,
Convert.ToInt32(SubscriptionType.Both,
System.Globalization.CultureInfo.InvariantCulture));
// Enumerate all subscriptions
this.subscriptionsComboBox.BeginUpdate();
// Empty the combo box
this.subscriptionsComboBox.Items.Clear();
this.subscriptionsComboBox.Text = string.Empty;
foreach (SubscriberSubscription subscriberSubscription
in availableSubscriptions)
{
// Only get subscriptions to merge publications.
if (subscriberSubscription.Type == PublicationType.Merge)
{
subId = "[" + subscriberSubscription.SubscriptionDBName
+ "]-[" + subscriberSubscription.PublisherName
+ " ].[" + subscriberSubscription.PublicationDBName
+ "]:" + subscriberSubscription.PublicationName;
subscriberSubscription.UserData = subId;
this.subscriptionsComboBox.Items.Add(subscriberSubscription.UserData);
if (subId.Length > subTextLength)
{
subTextLength = subId.Length;
}
}
}
this.subscriptionsComboBox.DropDownWidth = Convert.ToInt32(subTextLength * 5.6);
// Set to the first item to get subscription properties.
if (this.subscriptionsComboBox.Items.Count > 0)
{
this.subscriptionsComboBox.SelectedIndex = 0;
}
this.subscriptionsComboBox.EndUpdate();
}
catch (Exception ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
}
}
示例14: Run
void Run(ref AppArgs parsedArgs)
{
ServerConnection sc = new ServerConnection();
try
{
sc.ServerInstance = parsedArgs.Server;
sc.LoginSecure = parsedArgs.Integrated;
sc.StatementTimeout = 0;
if (!parsedArgs.Integrated)
{
sc.Login = parsedArgs.User;
sc.Password = parsedArgs.Password;
}
sc.Connect();
String command = parsedArgs.Command.ToLower();
String dbName = parsedArgs.Database;
String schName = parsedArgs.Schema;
String partitionTblName = parsedArgs.PartitionTable;
String scriptOption = (parsedArgs.ScriptOption == null) ? null : parsedArgs.ScriptOption.ToLower();
// Set flag indicating whether scripts will be generated
bool generateScript = (scriptOption == "i" || scriptOption == "o") ? true : false;
// set flag indicated whether commands will be executed on SQL Server (as opposed to just scripting)
bool executeCommands = (scriptOption == "o") ? false : true;
// Ensure that either a partition number or range value is provided, not both
int partitionNumber = parsedArgs.PartitionNumber;
string partitionRangeValue = parsedArgs.PartitionRangeValue;
if (((partitionRangeValue == null) && (partitionNumber == 0)) ||
((partitionRangeValue != null) && (partitionNumber != 0)))
{
throw new System.ArgumentException("Specify either a partition number OR a partition range value");
}
// Construct a staging table name likely to be unique, if no name is provided
String stagingTblName = parsedArgs.StagingTable;
if (stagingTblName == null)
{
stagingTblName = partitionTblName + "_part" + partitionNumber.ToString("####", System.Globalization.CultureInfo.InvariantCulture)
+ partitionRangeValue + "_" + System.DateTime.Now.Ticks.ToString(System.Globalization.CultureInfo.InvariantCulture);
}
bool keepStaging = parsedArgs.Keep;
PartitionManager pm = null;
System.IO.StreamWriter scriptWriter = null;
if ((scriptOption == "i" || scriptOption == "o")
&& parsedArgs.ScriptFile != null)
{
try
{
scriptWriter = new System.IO.StreamWriter(parsedArgs.ScriptFile, true, Encoding.Unicode);
}
catch (System.IO.IOException ex)
{
Console.WriteLine(ex.Message, ex.Source);
Console.WriteLine("Output will be sent to console instead");
}
}
using (scriptWriter)
{
// Call appropriate Partition Manager constructor depending on whether a partition number or range value is provided
if (partitionNumber != 0)
{
pm = new PartitionManagement.PartitionManager(sc, dbName, schName, partitionTblName,
stagingTblName, partitionNumber, scriptWriter, executeCommands);
}
else
{
pm = new PartitionManagement.PartitionManager(sc, dbName, schName, partitionTblName,
stagingTblName, partitionRangeValue, scriptWriter, executeCommands);
}
pm.SetTransactionIsolationLevelReaduncommitted();
switch (command)
{
case "clearpartition":
pm.CreateStgTable();
pm.CreateStgFkeys();
pm.CreateStgChecks();
pm.CreateStgPartitionCheck();
// If staging table is being deleted, no need to create non-clustered indexes & views
pm.CreateStgIndexes(keepStaging);
pm.ClearPartition(keepStaging);
if (generateScript) pm.outputScript();
break;
case "createstagingfull":
pm.CreateStgTable();
pm.CreateStgFkeys();
pm.CreateStgChecks();
pm.CreateStgPartitionCheck();
pm.CreateStgIndexes(true);
if (generateScript) pm.outputScript();
break;
//.........这里部分代码省略.........
示例15: ReinitializeSubscriptionWithUpload
public void ReinitializeSubscriptionWithUpload()
{
MergeSynchronizationAgent syncAgent;
try
{
// Make the connection and get the subscription properties.
subscriberConn = new ServerConnection(subscriberServer);
subscriberConn.Connect();
}
catch (Microsoft.SqlServer.Replication.ConnectionFailureException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(
Properties.Resources.ExceptionCannotConnectLocal,
Properties.Resources.ExceptionSqlServerError,
ExceptionMessageBoxButtons.OK);
emb.InnerException = ex;
emb.Show(this);
// Shutdown the application because we can't continue.
Application.Exit();
}
mergePullSub = new MergePullSubscription();
// Set the properties needed to get the subscription.
mergePullSub.ConnectionContext = subscriberConn;
mergePullSub.PublicationName = publicationName;
mergePullSub.PublisherName = publisherServer;
mergePullSub.PublicationDBName = publicationDatabase;
mergePullSub.DatabaseName = subscriptionDatabase;
// Load the properties of the existing subscription.
if (!mergePullSub.LoadProperties())
{
throw new ApplicationException(
Properties.Resources.ExceptionProblemLocalData
+ Environment.NewLine
+ Properties.Resources.ExceptionContactTechSupport);
}
// Check to make sure that the Merge Agent isn't already running.
if (mergePullSub.LastAgentStatus
!= (ReplicationStatus.Running | ReplicationStatus.Starting))
{
// Mark the subscription for reinitialization after uploading.
mergePullSub.Reinitialize(true);
// Get the Merge Agent for synchronous execution.
syncAgent = mergePullSub.SynchronizationAgent;
// Define the event handler.
syncAgent.Status
+= new AgentCore.StatusEventHandler(Sync_Status);
syncAgent.Output = outputLogFile;
syncAgent.OutputVerboseLevel = outputLevel;
// Start the Merge Agent Job.
try
{
currentStatusTextBox.Text = statusReinitialize
+ Environment.NewLine;
syncAgent.Synchronize();
}
catch (Exception ex)
{
throw new ApplicationException(
Properties.Resources.ExceptionCouldNotReInit
+ Environment.NewLine
+ Properties.Resources.ExceptionContactTechSupport, ex);
}
finally
{
statusProgressBar.Value = 100;
closeButton.Enabled = true;
subscriberConn.Disconnect();
}
}
else
{
currentStatusTextBox.Text
= Properties.Resources.StatusSubscriptionAlreadySync;
closeButton.Enabled = true;
}
}