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


C# SqlServer类代码示例

本文整理汇总了C#中SqlServer的典型用法代码示例。如果您正苦于以下问题:C# SqlServer类的具体用法?C# SqlServer怎么用?C# SqlServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Get_Table_Definition

 public void Get_Table_Definition()
 {
     var server = new SqlServer();
     var table = server.GetTableDefinition("localhost", "master", "spt_fallback_db");
     table.ShouldNotBeNull();
     table.Columns.Count().ShouldNotEqual(0);
 }
开发者ID:mikeobrien,项目名称:VisualStudioWizardAndTemplateExploration,代码行数:7,代码来源:SqlServerTests.cs

示例2: SqlServer_Connect_UserIDInDomainFormat_ConnectionStringIsNotIntegratedSecurityEqualsSSPI

        public void SqlServer_Connect_UserIDInDomainFormat_ConnectionStringIsNotIntegratedSecurityEqualsSSPI()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
            dbSource.UserID = "Dev2\\TestUser";

            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                try
                {
                    // expect this call to throw a 'login failed' exception
                    sqlServer.Connect(dbSource.ConnectionString);
                }
                // ReSharper disable EmptyGeneralCatchClause
                catch
                // ReSharper restore EmptyGeneralCatchClause
                {
                }

                //------------Assert Results-------------------------
                Assert.IsFalse(sqlServer.ConnectionString.Contains("Integrated Security=SSPI"));
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:29,代码来源:SqlServerTests.cs

示例3: SqlDataBase

 /// <summary>
 /// �õ�ʵ��
 /// </summary>
 /// <returns></returns>
 public static SqlServer SqlDataBase()
 {
     if (_SqlDataBase == null)
     {
         _SqlDataBase = new Universal_ClassLibrary.DataBase.SqlServer(ConfigHelper.GetAppSettings("SqlServer_NewSaaS"));
     }
     return _SqlDataBase;
 }
开发者ID:txy-cs,项目名称:NewSaas,代码行数:12,代码来源:DataFactory.cs

示例4: FecharCaixa

        public void FecharCaixa()
        {
            var impostos = 200;
            var database = new SqlServer();
            var vendas = database.Selecionar("Dinheiro em caixa");
            var vendasDeOntem = database.Selecionar("Dinheiro em caixa de ontem");

            var totalDeVendas = vendas - vendasDeOntem;
            totalDeVendas = totalDeVendas - impostos;

            database.Atualizar("vendas líquidas", totalDeVendas.ToString());
            database.Deletar("venda bruta");
        }
开发者ID:ricardovsilva,项目名称:uso-de-interfaces,代码行数:13,代码来源:AdministradorVendas.cs

示例5: Should_replace_where_with_included_databases

        public void Should_replace_where_with_included_databases()
        {
            var queryType = new SqlServerConnections();

            var sqlServer = new SqlServer("foo", "foo", true, new[] {new Database {Name = "bar"},}, null);

            var queryLocator = new QueryLocator(null);
            var queries = queryLocator.PrepareQueries(new[] {queryType.GetType()}, false);
            foreach (var query in queries)
            {
                var actual = queryType.ParameterizeQuery(query.CommandText, sqlServer);
                Assert.That(actual, Is.StringContaining("AND (d.Name IN ('bar')"));
            }
        }
开发者ID:jamierytlewski,项目名称:newrelic_microsoft_sqlserver_plugin,代码行数:14,代码来源:ConnectionsTests.cs

示例6: Test_Type_SQLServerDatabase

        public void Test_Type_SQLServerDatabase()
        {
            // Define tipo Sql
            AbstractDataBase dataBase = new SqlServer();
            // Atribuindo command
            DbCommand cmd = dataBase.Command;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT, DELETE, INSERT, UPDATE";
            cmd.Connection.Open();
            DbDataReader reader = cmd.ExecuteReader();
            reader.Close();
            cmd.Connection.Close();

            Assert.IsInstanceOfType(dataBase, typeof(SqlServer));
        }
开发者ID:esouzagithub,项目名称:AbstractFactory,代码行数:15,代码来源:TestAbstractFactory.cs

示例7: SqlServer_Connect_CommandTextIsNull_ThrowsArgumentNullException

// ReSharper disable InconsistentNaming
        public void SqlServer_Connect_CommandTextIsNull_ThrowsArgumentNullException()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect("Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=SSPI;", CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:18,代码来源:SqlServerTests.cs

示例8: SqlServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException

// ReSharper disable InconsistentNaming
        public void SqlServer_Connect_ConnectionStringIsInvalid_ThrowsArgumentException()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect("xxx", CommandType.Text, null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:18,代码来源:SqlServerTests.cs

示例9: SqlServer_Connect_ValidLogin_IsConnectedIsTrue

        public void SqlServer_Connect_ValidLogin_IsConnectedIsTrue()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Assert Results-------------------------
                Assert.IsTrue(sqlServer.IsConnected);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:19,代码来源:SqlServerTests.cs

示例10: SqlServer_Connect_InvalidLogin_ThrowsSqlException

        public void SqlServer_Connect_InvalidLogin_ThrowsSqlException()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();
            dbSource.Password = Guid.NewGuid().ToString(); // Random invalid password

            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:19,代码来源:SqlServerTests.cs

示例11: SqlServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException

// ReSharper disable InconsistentNaming
        public void SqlServer_FetchDatabases_ConnectionNotInitialized_ThrowsConnectFirstException()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDatabases();

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:18,代码来源:SqlServerTests.cs

示例12: SqlServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException

// ReSharper disable InconsistentNaming
        public void SqlServer_FetchDataTable_CommandIsNull_ThrowsArgumentNullException()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var sqlServer = new SqlServer();
            try
            {
                //------------Execute Test---------------------------
                sqlServer.FetchDataTable((IDbCommand)null);

                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:18,代码来源:SqlServerTests.cs

示例13: Execute_Arbitrary_Sql

 public void Execute_Arbitrary_Sql()
 {
     var server = new SqlServer();
     Assert.DoesNotThrow(() => server.Execute("localhost", "master", "SELECT COUNT(*) FROM sys.databases"));
 }
开发者ID:mikeobrien,项目名称:VisualStudioWizardAndTemplateExploration,代码行数:5,代码来源:SqlServerTests.cs

示例14: SqlServer_FetchDataSet_CorrectDataReturned

        public void SqlServer_FetchDataSet_CorrectDataReturned()
        {
            //------------Setup for test--------------------------
            var dbSource = SqlServerTestUtils.CreateDev2TestingDbSource();

            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString, CommandType.StoredProcedure, "Pr_CitiesGetCountries");

                //------------Execute Test---------------------------
                var actualDataSet = sqlServer.FetchDataSet(new SqlParameter("@Prefix", "a"));

                //------------Assert Results-------------------------
                Assert.AreEqual(1, actualDataSet.Tables.Count);

                var actual = actualDataSet.Tables[0];

                SqlServerTestUtils.Verify_DataTable_CountriesPrefixIsA(actual);
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:25,代码来源:SqlServerTests.cs

示例15: SqlServer_FetchStoredProcedures_FuncReturnsSPs

// ReSharper disable InconsistentNaming
        public void SqlServer_FetchStoredProcedures_FuncReturnsSPs()
// ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var factory = new Mock<IDbFactory>();
            var mockCommand = new Mock<IDbCommand>();
            var mockReader = new Mock<IDataReader>();
            var queue = new Queue<DataTable>();

            mockCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Returns(mockReader.Object);
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");

            var helpTextCommand = new Mock<IDbCommand>();
            helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Returns(new Mock<IDataReader>().Object);
            var somethingAdded = false;
            var funcAdded = false;
            factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.Text, GlobalConstants.SchemaQuery)).Returns(mockCommand.Object);
            factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.StoredProcedure, "Dave.Bob")).Returns(mockCommand.Object);
            factory.Setup(a => a.CreateCommand(It.IsAny<IDbConnection>(), CommandType.Text, "sp_helptext 'Dave.Bob'")).Returns(helpTextCommand.Object);
            DataTable dt = new DataTable();
            dt.Columns.Add("ROUTINE_NAME");
            dt.Columns.Add("ROUTINE_TYPE");
            dt.Columns.Add("SPECIFIC_SCHEMA");
            dt.Rows.Add(new object[] { "Bob", "SQL_SCALAR_FUNCTION", "Dave" });
            queue.Enqueue(dt);

            queue.Enqueue(new DataTable()); // no params

            factory.Setup(a => a.CreateTable(mockReader.Object, LoadOption.OverwriteChanges)).Returns(queue.Dequeue);
            var conn = new Mock<IDbConnection>();
            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            var sqlServer = new SqlServer(factory.Object);
            try
            {
                PrivateObject pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                //------------Execute Test---------------------------
                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> procProcessor = (command, list, arg3, a) =>
                {
                    somethingAdded = true; return true;
                };
                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> funcProcessor = (command, list, arg3, a) =>
                {
                    funcAdded = true; return true;
                };

                sqlServer.FetchStoredProcedures(procProcessor, funcProcessor);
                Assert.IsTrue(funcAdded);
                Assert.IsFalse(somethingAdded);



                //------------Assert Results-------------------------
            }
            finally
            {
                sqlServer.Dispose();
            }
        }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:60,代码来源:SqlServerTests.cs


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