本文整理汇总了C#中ServerConnection类的典型用法代码示例。如果您正苦于以下问题:C# ServerConnection类的具体用法?C# ServerConnection怎么用?C# ServerConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerConnection类属于命名空间,在下文中一共展示了ServerConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDefinitions
public System.Collections.Generic.IReadOnlyList<TableDefinition> GetDefinitions(ISqlConnectionProvider sqlConnectionProvider)
{
var conn = sqlConnectionProvider.GetConnection();
var dbName = conn.Database;
var serverConnection = new ServerConnection(conn);
var server = new Server(serverConnection);
var scripter = new Scripter(server);
scripter.Options.ScriptDrops = false;
scripter.Options.WithDependencies = false;
scripter.Options.NoCollation = true;
var db = server.Databases[dbName];
var results = new List<TableDefinition>();
foreach (Table table in db.Tables)
{
if (table.IsSystemObject)
continue;
var id = table.ID;
var definitions = scripter.Script(new Urn[] {table.Urn});
var sb = new StringBuilder();
foreach (var definition in definitions)
{
sb.AppendLine(definition);
}
var flattened = sb.ToString();
results.Add(new TableDefinition(id, flattened));
}
return results;
}
示例2: ReplaceDatabase
public void ReplaceDatabase(string connectionString, string dbReplacementPath)
{
var connection = new SqlConnectionStringBuilder(connectionString);
var databaseName = connection.InitialCatalog;
if (!File.Exists(dbReplacementPath))
{
Log.Error($"Can't find file by path {dbReplacementPath}", this);
return;
}
ServerConnection serverConnection = null;
try
{
serverConnection = new ServerConnection(new SqlConnection(connectionString));
var server = new Server(serverConnection);
if (server.Databases[databaseName] != null)
{
server.KillAllProcesses(databaseName);
server.DetachDatabase(databaseName, true);
}
server.AttachDatabase(databaseName,new StringCollection() {dbReplacementPath}, AttachOptions.RebuildLog);
}
catch (Exception ex)
{
Log.Error(ex.Message, ex, this);
}
finally
{
serverConnection?.Disconnect();
}
}
示例3: Execute
public bool Execute(ApplyTaskConfiguration configuration, GusTaskExecutionContext context)
{
var databaseHelper = new DatabaseHelper(context);
var fileSystemHelper = new FileSystemHelper(context);
var connection = databaseHelper.CreateAndOpenConnection(configuration.Server);
if (connection == null)
{
return false;
}
var serverConnection = new ServerConnection(connection);
var server = new Server(serverConnection);
var database = databaseHelper.InitializeDatabase(server, configuration.Database, configuration.CreateDatabaseIfMissing, configuration.CreateDatabaseIfMissing || configuration.CreateManagementSchemaIfMissing);
if (database == null)
{
return false;
}
context.RaiseExecutionEvent("Determining scripts to apply.");
var scriptsToApply = GetScriptsToApply(configuration.SourcePath, database, databaseHelper, fileSystemHelper);
if (scriptsToApply == null)
{
return false;
}
context.ExecutionStepCount = (uint)scriptsToApply.Count;
context.RaiseExecutionEvent(string.Format("Found {0} scripts to apply.", scriptsToApply.Count));
var success = ApplyScripts(scriptsToApply, server, database, databaseHelper, fileSystemHelper, configuration.RecordOnly, context, configuration.HaltOnError);
return success;
}
示例4: ParseTablesTest
public void ParseTablesTest()
{
// # Arrange.
const string DatabaseName = "ParseTablesTest.mdf";
var connectionString = string.Format(ConnectionStringTemplate,
Path.Combine( Common.Functions.SolutionPath(TestContext), DatabasePath, DatabaseName));
IList<Table> tables;
using (var conn = new SqlConnection(connectionString))
{
var serverConnection = new ServerConnection(conn);
var server = new Server(serverConnection);
var database = server.Databases[
Path.Combine(Common.Functions.SolutionPath(TestContext), DatabasePath, DatabaseName)];
tables = ServerInfo.UT_GetTablesByDatabasePrivate(database);
}
var sut = new ParserLogic();
// # Act.
var res = sut.Parse(tables, "Project");
// # Assert.
Assert.AreEqual(3, res.Tables.Count);
var projectTable = res.Tables.Single(t => t.Name == "Project");
Assert.IsFalse(projectTable.Include);
var customerTable = res.Tables.Single(t => t.Name == "Customer");
Assert.IsTrue(customerTable.Include);
var userTable = res.Tables.Single(t => t.Name == "User");
Assert.IsTrue(userTable.Include);
}
示例5: SQLObjects
public SQLObjects()
{
//GetServers();
var instances = GetInstances(true);
var connection = new ServerConnection(@"Brian-THINK\Lenovo", "brian", "brian");
var server = GetServer(connection);
//var t = Microsoft.SqlServer.Management.Smo.NamedSmoObject
//var foreignKeys = Microsoft.SqlServer.Management.Smo.ForeignKey
//var foreignKeyColumns = Microsoft.SqlServer.Management.Smo.ForeignKeyColumn
//var fullTextIndicies = Microsoft.SqlServer.Management.Smo.FullTextIndex
//var logins = Microsoft.SqlServer.Management.Smo.Login
var db = GetDatabase(server, "MiGANG");
var foreignKeys = GetForeignKeys(db);
var foreignKeyss = GetForeignKeys(db, new Table(db, "Meetings"));
//Database database = server.Databases[1];
//GetPrimaryKeys(database);
//GetForeignKeys(database);
//Database db = server.Databases.Cast<Database>().Where(x => x.Name == "MiGANG").SingleOrDefault();
//DatabaseObjects dbo = new DatabaseObjects(database);
}
示例6: LoadDatabase
private static void LoadDatabase()
{
//Connect to the server
var connectionString = "Data Source=localhost\\sqlexpress;Initial Catalog=master;Integrated Security=SSPI";
var con = new SqlConnection(connectionString);
ServerConnection serverConnection = new ServerConnection(con);
Server sqlServer = new Server(serverConnection);
System.IO.FileInfo mdf = new System.IO.FileInfo(@"Buzzle.mdf");
System.IO.FileInfo ldf = new System.IO.FileInfo(@"Buzzle_log.LDF");
var dbPath = sqlServer.MasterDBPath;
var databasePath = dbPath + @"\Buzzle.mdf";
var databaseLogPath = dbPath + @"\Buzzle_log.LDF";
File.Copy(mdf.FullName, databasePath, true);
File.Copy(ldf.FullName, databaseLogPath, true);
var databasename = mdf.Name.ToLower().Replace(@".mdf", @"");
System.Collections.Specialized.StringCollection databasefiles = new System.Collections.Specialized.StringCollection();
databasefiles.Add(databasePath);
databasefiles.Add(databaseLogPath);
sqlServer.AttachDatabase(databasename, databasefiles);
}
示例7: SqlServerManager
public SqlServerManager(string serverName, string instanceName)
{
string path = string.Format(@"{0}\{1}", serverName, instanceName);
ServerConnection connection = new ServerConnection(path) {LoginSecure = true};
_server = new Server(connection);
}
示例8: Main
static void Main(string[] args) {
// Configure Resource manager
string path = System.Configuration.ConfigurationSettings.AppSettings["ResourcePath"];
if ( path == null ) {
//throw new System.Configuration.ConfigurationException( "ResourcePath" );
}
CurrentMessageProcessor = new MessageProcessor();
// Initialise required objects
CurrentServerConnection = new ServerConnection();
CurrentServerConnection.OnConnect += new ServerConnection.OnConnectHandler( HandleConnect );
CurrentServerConnection.OnDisconnect += new ServerConnection.OnDisconnectHandler( HandleDisconnect );
CurrentMainWindow = new Windows.Main();
CurrentMainWindow.Show();
//CurrentWorld.InitialiseView( CurrentMainWindow, CurrentMainWindow.RenderTarget, CurrentMainWindow.miniMap.RenderTarget );
Windows.ChildWindows.Connection con = new Windows.ChildWindows.Connection();
con.Show();
while( !CurrentMainWindow.IsDisposed ) {
// NB: This is a tight renderloop
// it will chew cpu
// TODO: could be made nicer by
// P/Invoke into the Win32 API and call PeekMessage/TranslateMessage/DispatchMessage. (Doevents actually does something similar, but you can do this without the extra allocations).
Application.DoEvents();
if ( CurrentServerConnection.isRunning ) {
GameLoop();
}
System.Threading.Thread.Sleep( 0 );
}
// must terminate all threads to quit
CurrentServerConnection.Stop();
}
示例9: ManageTables_Load
private void ManageTables_Load(object sender, System.EventArgs e)
{
ServerConnection ServerConn;
ServerConnect scForm;
DialogResult dr;
// Display the main window first
this.Show();
Application.DoEvents();
ServerConn = new ServerConnection();
scForm = new ServerConnect(ServerConn);
dr = scForm.ShowDialog(this);
if ((dr == DialogResult.OK) &&
(ServerConn.SqlConnectionObject.State == ConnectionState.Open))
{
SqlServerSelection = new Server(ServerConn);
if (SqlServerSelection != null)
{
this.Text = Properties.Resources.AppTitle + SqlServerSelection.Name;
// Refresh database list
ShowDatabases(true);
}
}
else
{
this.Close();
}
}
示例10: RestoreDatabase
public void RestoreDatabase(SqlConnectionStringBuilder sqlConnection, String backUpFile)
{
ServerConnection serverConnection = null;
try
{
if (!FileManager.FileExists(backUpFile))
{
throw new FileNotFoundException();
}
serverConnection = new ServerConnection(sqlConnection.DataSource, sqlConnection.UserID, sqlConnection.Password);
Server sqlServer = new Server(serverConnection);
Restore restoreDatabase = new Restore()
{
Action = RestoreActionType.Database,
Database = sqlConnection.InitialCatalog,
};
BackupDeviceItem backupItem = new BackupDeviceItem(backUpFile, DeviceType.File);
restoreDatabase.Devices.Add(backupItem);
restoreDatabase.ReplaceDatabase = true;
restoreDatabase.SqlRestore(sqlServer);
}
finally
{
if (serverConnection != null && serverConnection.IsOpen)
{
serverConnection.Disconnect();
}
}
}
示例11: ddlCatalog_DropDown
private void ddlCatalog_DropDown(object sender, EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
if (ddlAuthType.Text == "SQL Server Authentication")
{
ServerConnection svrConn = new ServerConnection(tbServerName.Text);
svrConn.LoginSecure = false;
svrConn.Login = tbLogin.Text;
svrConn.Password = tbPassword.Text;
_SourceServer = new Server(svrConn);
}
else
_SourceServer = new Server(tbServerName.Text);
ddlCatalog.Items.Clear();
try
{
foreach (Database db in _SourceServer.Databases)
{
ddlCatalog.Items.Add(db.Name);
}
}
catch (ConnectionFailureException ex)
{
MessageBox.Show(this, ex.Message, "Connection Failed!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
this.Cursor = Cursors.Default;
}
}
示例12: UserEditorViewModel
/// <summary>
/// Constructor of the class. Sets up the commands, variables and the sql-connection.
/// </summary>
/// <param name="adminLogIn">Login data of the admin account.</param>
public UserEditorViewModel(Views.Utils.LogIn adminLogIn)
{
AddUserCommand = new RelayCommand(() => _AddUserCommand(), () => true);
RemoveUserCommand = new RelayCommand(() => _RemoveUserCommand(), () => true);
DownloadDatabaseCommand = new RelayCommand(() => _BackupDatabaseCommand(), () => true);
AdminLogIn = adminLogIn;
sqlConnection = new SqlConnection(@"Data Source = " + adminLogIn.IPAdress + ", " + adminLogIn.Port + "; Network Library = DBMSSOCN; User ID = " + adminLogIn.UserName + "; Password = " + adminLogIn.Password + "; ");
//ServerConnection serverConnection = new ServerConnection(sqlConnection);
ServerConnection serverConnection = new ServerConnection(adminLogIn.IPAdress + ", " + adminLogIn.Port);
server = new Server(serverConnection);
server.ConnectionContext.LoginSecure = false;
server.ConnectionContext.Login = adminLogIn.UserName;
server.ConnectionContext.Password = adminLogIn.Password;
try
{
string temp = server.Information.Version.ToString(); // connection is established
}
catch (ConnectionFailureException e)
{
MessageBox.Show("Login error: " + e.Message, "Error");
DialogResult = false;
return;
}
Users = new ObservableCollection<MyUser>();
FillUserList();
}
示例13: RunScript
public static void RunScript(string scriptText)
{
SqlConnection sqlConnection = new SqlConnection(Settings.Default.TestDb);
ServerConnection svrConnection = new ServerConnection(sqlConnection);
Server server = new Server(svrConnection);
server.ConnectionContext.ExecuteNonQuery(scriptText);
}
示例14: TestServerConnection
public void TestServerConnection()
{
ServerConnection sc = new ServerConnection();
// User information.
string emailAddress = "[email protected]";
string password = "1234";
sc.Login(
emailAddress,
password,
new EventDelegates.HTTPResponseDelegate(ProcessResponse),
new EventDelegates.HTTPFailDelegate(FailRequest));
sc.GetSightsList(
new EventDelegates.HTTPResponseDelegate(ProcessResponse),
new EventDelegates.HTTPFailDelegate(FailRequest));
// Load photo from file.
Uri uri = new Uri("img.jpg", UriKind.Relative);
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri);
Stream imageStream = streamResourceInfo.Stream;
int imageSize = (int)imageStream.Length;
BinaryReader binReader = new BinaryReader(imageStream);
byte[] imageBytes = new byte[imageSize];
int count = binReader.Read(imageBytes, 0, (int)imageSize);
binReader.Close();
sc.UploadPhoto(
4, // my user ID
imageBytes,
new EventDelegates.HTTPResponseDelegate(ProcessResponse),
new EventDelegates.HTTPFailDelegate(FailRequest));
}
示例15: SqlObjectBrowser
public SqlObjectBrowser(ServerConnection serverConn)
{
InitializeComponent();
// Connect to SQL Server
server = new Server(serverConn);
try
{
server.ConnectionContext.Connect();
// In case connection succeeded we add the sql server node as root in object explorer (treeview)
TreeNode tn = new TreeNode();
tn.Text = server.Name;
tn.Tag = server.Urn;
this.objUrn = server.Urn;
objectBrowserTreeView.Nodes.Add(tn);
AddDummyNode(tn);
connected = true;
}
catch (ConnectionException)
{
ExceptionMessageBox emb = new ExceptionMessageBox();
emb.Text = Properties.Resources.ConnectionFailed;
emb.Show(this);
}
catch (ApplicationException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
}
}