当前位置: 首页>>代码示例>>C#>>正文


C# ServerConnection.ExecuteNonQuery方法代码示例

本文整理汇总了C#中ServerConnection.ExecuteNonQuery方法的典型用法代码示例。如果您正苦于以下问题:C# ServerConnection.ExecuteNonQuery方法的具体用法?C# ServerConnection.ExecuteNonQuery怎么用?C# ServerConnection.ExecuteNonQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ServerConnection的用法示例。


在下文中一共展示了ServerConnection.ExecuteNonQuery方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExecuteSql

        protected void ExecuteSql(string sql)
        {
            using (var connection = new SqlConnection(this.ConnectionString))
            {
                var serverConnection = new ServerConnection(connection);

                serverConnection.ExecuteNonQuery(sql);
            }
        }
开发者ID:cameronfletcher,项目名称:meld,代码行数:9,代码来源:SqlServerFeature.cs

示例2: CreateDatabase

		public static void CreateDatabase(Identifier claimedId, string friendlyId, string databaseName) {
			const string SqlFormat = @"
{0}
GO
EXEC [dbo].[AddUser] 'admin', 'admin', '{1}', '{2}'
GO
";
			var removeSnippets = new string[] { @"
IF IS_SRVROLEMEMBER(N'sysadmin') = 1
    BEGIN
        IF EXISTS (SELECT 1
                   FROM   [master].[dbo].[sysdatabases]
                   WHERE  [name] = N'$(DatabaseName)')
            BEGIN
                EXECUTE sp_executesql N'ALTER DATABASE [$(DatabaseName)]
    SET HONOR_BROKER_PRIORITY OFF 
    WITH ROLLBACK IMMEDIATE';
            END
    END
ELSE
    BEGIN
        PRINT N'The database settings cannot be modified. You must be a SysAdmin to apply these settings.';
    END


GO" };
			string databasePath = HttpContext.Current.Server.MapPath("~/App_Data/" + databaseName + ".mdf");
			StringBuilder schemaSqlBuilder = new StringBuilder();
			using (var sr = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(DefaultNamespace + ".CreateDatabase.sql"))) {
				schemaSqlBuilder.Append(sr.ReadToEnd());
			}
			foreach (string remove in removeSnippets) {
				schemaSqlBuilder.Replace(remove, string.Empty);
			}
			schemaSqlBuilder.Replace("$(Path1)", HttpContext.Current.Server.MapPath("~/App_Data/"));
			schemaSqlBuilder.Replace("WEBROOT", databasePath);
			schemaSqlBuilder.Replace("$(DatabaseName)", databaseName);

			string sql = string.Format(CultureInfo.InvariantCulture, SqlFormat, schemaSqlBuilder, claimedId, "Admin");

			var serverConnection = new ServerConnection(".\\sqlexpress");
			try {
				serverConnection.ExecuteNonQuery(sql);
			} finally {
				try {
					var server = new Server(serverConnection);
					server.DetachDatabase(databaseName, true);
				} catch (FailedOperationException) {
				}
				serverConnection.Disconnect();
			}
		}
开发者ID:jorgemuza,项目名称:dotnetopenid,代码行数:52,代码来源:Utilities.cs

示例3: InvokeHandler

        public override void InvokeHandler(CommandSetState state)
        {
            var diagram = state.CurrentDocView.CurrentDiagram;
            var modelRoot = diagram.Store.ElementDirectory.FindElements<ModelRoot>().Single();
            var connectionString = modelRoot.ConnectionString;

            var dlg = new GenerateSQLForm();
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                var sqlGenerator = new DbSchemaGenerator(diagram)
                {
                    CleanUpDbSchema = dlg.CleanupDbSchema,
                    UseNavigationPropertyNameForFKeys = dlg.UseNavigationPropertyNameForFKeys,
                };
                var sb = sqlGenerator.GenerateScripts();
                System.IO.File.WriteAllText(dlg.Filename, sb.ToString());

                if (dlg.OverwriteDatabase)
                {
                    //Creating a connection to the given database
                    using (SqlConnection sqlConnection = new SqlConnection(connectionString))
                    {
                        var originalDatabase = sqlConnection.Database;
                        sqlConnection.Open();

                        //Switching to master database
                        sqlConnection.ChangeDatabase("master");
                        ServerConnection svrConnection = new ServerConnection(sqlConnection);

                        //Recreating database and executing the query file
                        DropAndRecreateDatabase(originalDatabase, svrConnection);
                        svrConnection.ExecuteNonQuery(System.IO.File.ReadAllText(dlg.Filename));
                    }

                    ModelerTransaction.Enter(() =>
                        {

                            //Importing the new schema from database
                            var sync = new Utilities.DbSchemaImporter(diagram);
                            sync.FullDatabaseReload = true;
                            sync.ImportModels();
                        });
                }
                System.Windows.Forms.MessageBox.Show("Sql script generation completed.");
            }
        }
开发者ID:jeswin,项目名称:AgileFx,代码行数:46,代码来源:GenerateDbSchemaCommand.cs

示例4: 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;
 }
开发者ID:JC-Developers,项目名称:SoftEmpeniosCergo,代码行数:39,代码来源:clsCreacionDB.cs

示例5: DropAndRecreateDatabase

 private void DropAndRecreateDatabase(string databaseName, ServerConnection connection)
 {
     var commandText =
     @"USE [master]
     IF EXISTS(SELECT * FROM sys.databases WHERE NAME = '{0}')
     BEGIN
         ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
         DROP DATABASE [{0}]
     END
     CREATE DATABASE [{0}]
     GO";
     connection.ExecuteNonQuery(string.Format(commandText, databaseName));
 }
开发者ID:jeswin,项目名称:AgileFx,代码行数:13,代码来源:GenerateDbSchemaCommand.cs


注:本文中的ServerConnection.ExecuteNonQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。