本文整理汇总了C#中ServerConnection类的典型用法代码示例。如果您正苦于以下问题:C# ServerConnection类的具体用法?C# ServerConnection怎么用?C# ServerConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerConnection类属于命名空间,在下文中一共展示了ServerConnection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:crispingiles,项目名称:SqlDBCopier,代码行数:31,代码来源:TableDefinitionProvider.cs
示例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();
}
}
开发者ID:kamsar,项目名称:Habitat,代码行数:33,代码来源:DatabaseService.cs
示例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;
}
开发者ID:defize,项目名称:Gus,代码行数:34,代码来源:ApplyTask.cs
示例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);
}
开发者ID:LosManos,项目名称:St4mpede,代码行数:33,代码来源:ParserLogicTest.cs
示例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);
}
开发者ID:Codeslingers,项目名称:SQL-Objects,代码行数:28,代码来源:SQLObjects.cs
示例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);
}
开发者ID:titusxp,项目名称:buzzle,代码行数:26,代码来源:Program.cs
示例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);
}
开发者ID:Ashna,项目名称:ShayanDent,代码行数:7,代码来源:SqlServerManager.cs
示例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();
}
开发者ID:628426,项目名称:Strive.NET,代码行数:35,代码来源:Game.cs
示例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();
}
}
开发者ID:rcdosado,项目名称:SMO,代码行数:30,代码来源:ManageTables.cs
示例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();
}
}
}
开发者ID:egormozzharov,项目名称:packageManager,代码行数:29,代码来源:DbService.cs
示例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;
}
}
开发者ID:sridhar19091986,项目名称:htmlconvertsql,代码行数:33,代码来源:SourceCtrl.cs
示例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();
}
开发者ID:Emanuesson,项目名称:newRBS,代码行数:35,代码来源:UserEditorViewModel.cs
示例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);
}
开发者ID:xtrmstep,项目名称:RunningTSQLwithGOscripts,代码行数:7,代码来源:SqlRuner.cs
示例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));
}
开发者ID:andabereczky,项目名称:GeoSightWinPhone7,代码行数:34,代码来源:ServerConnectionTest.cs
示例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);
}
}
开发者ID:rcdosado,项目名称:SMO,代码行数:33,代码来源:SqlObjectBrowser.cs
示例16: LoadRegAssembly_Load
private void LoadRegAssembly_Load(object sender, System.EventArgs e)
{
ServerConnection myServerConn;
ServerConnect scForm;
DialogResult dr;
// Display the main window first
this.Show();
Application.DoEvents();
myServerConn = new ServerConnection();
scForm = new ServerConnect(myServerConn);
dr = scForm.ShowDialog(this);
if ((dr == DialogResult.OK) &&
(myServerConn.SqlConnectionObject.State
== ConnectionState.Open))
{
mySqlServer = new Server(myServerConn);
if (mySqlServer != null)
{
this.Text = Properties.Resources.AppTitle + mySqlServer.Name;
// Refresh database list
ShowDatabases(true);
UpdateButtons();
}
}
else
{
this.Close();
}
}
开发者ID:rcdosado,项目名称:SMO,代码行数:32,代码来源:LoadRegAssembly.cs
示例17: CreateDatabase
public void CreateDatabase()
{
var connectoinStringBuilder = new SqlConnectionStringBuilder(ConnectionString);
string dbName = connectoinStringBuilder.InitialCatalog;
connectoinStringBuilder.InitialCatalog = string.Empty;
using (var connection = new SqlConnection(connectoinStringBuilder.ToString()))
{
try
{
var serverConnection = new ServerConnection(connection);
var server = new Microsoft.SqlServer.Management.Smo.Server(serverConnection);
var db = new Database(server, dbName);
db.Create();
}
catch (Exception e)
{
throw new Exception(string.Format("Ошибка при создании БД - {0}", e));
}
finally
{
if (connection.State == ConnectionState.Open)
{
connection.Close();
}
}
}
}
开发者ID:Drake103,项目名称:ewg,代码行数:28,代码来源:DbInitializer.cs
示例18: MakeRestore
public static void MakeRestore(ServerMessageEventHandler onComplete, Guid id,
string serverName, string dbName, string uncDir, string userName, string password)
{
var sc = new ServerConnection(serverName);
sc.LoginSecure = false;
sc.Login = userName;
sc.Password = password;
var srv = new Server(sc);
var rest = new Restore();
rest.Action = RestoreActionType.Database;
rest.Database = dbName;
rest.Devices.AddDevice(Path.Combine(uncDir, rest.Database + ".bak"), DeviceType.File);
rest.ReplaceDatabase = true;
var headers = rest.ReadBackupHeader(srv);
var query = from DataRow row in headers.Rows
where (string)row["BackupName"] == id.ToString()
select (Int16)row["Position"];
rest.FileNumber = query.First();
if (onComplete != null) rest.Complete += onComplete;
rest.SqlRestore(srv);
}
开发者ID:A-n-d-r-e-y,项目名称:VISLAB,代码行数:26,代码来源:SQLAdmin.cs
示例19: GetJob
public Job GetJob()
{
ServerConnection connection = new ServerConnection("mi001-ws00071", "SA", "Oberon");
connection.Connect();
Server jobserver = new Server(connection);
return jobserver.JobServer.Jobs["PVX"];
}
开发者ID:pvx,项目名称:ShopOrder,代码行数:7,代码来源:OrderManagerForm.cs
示例20: 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>");
}
}
开发者ID:RainSong,项目名称:Sample,代码行数:25,代码来源:index.aspx.cs
注:本文中的ServerConnection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论