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


C# SqlServer.Connect方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: SqlServer_Connect_SetsCommandType

 // ReSharper disable InconsistentNaming
 public void SqlServer_Connect_SetsCommandType()
 // ReSharper restore InconsistentNaming
 {
     //------------Setup for test--------------------------
     var factory = new Mock<IDbFactory>();
     var mockCommand = new Mock<IDbCommand>();
     mockCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Returns(new Mock<IDataReader>().Object);
     mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
     var added = new SqlCommand().Parameters;
     mockCommand.Setup(a => a.Parameters).Returns(added);
     var helpTextCommand = new Mock<IDbCommand>();
     helpTextCommand.Setup(a => a.ExecuteReader(It.IsAny<CommandBehavior>())).Returns(new Mock<IDataReader>().Object);
     DataTable dt = new DataTable();
     dt.Columns.Add("database_name");
     dt.Rows.Add(new object[] { "Bob" });
     dt.Rows.Add(new object[] { "Dave" });
     factory.Setup(a => a.GetSchema(It.IsAny<IDbConnection>(), "Databases")).Returns(dt);
     var conn = new Mock<IDbConnection>();
     conn.Setup(a => a.State).Returns(ConnectionState.Open);
     conn.Setup(a => a.ConnectionString).Returns("bob");
     factory.Setup(a => a.CreateConnection(It.IsAny<string>())).Returns(conn.Object);
     var sqlServer = new SqlServer(factory.Object);
     try
     {
         //------------Execute Test---------------------------
         sqlServer.Connect("bob", CommandType.StoredProcedure, "select * from ");
         factory.Verify(a => a.CreateCommand(conn.Object, CommandType.Text, "select * from "));
     }
     finally
     {
         sqlServer.Dispose();
     }
 }
开发者ID:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:34,代码来源:SqlServerTests.cs

示例6: 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:NatashaSchutte,项目名称:Warewolf-ESB,代码行数:18,代码来源:SqlServerTests.cs

示例7: SqlServer_FetchStoredProcedures_RollbackTransaction

        // ReSharper disable InconsistentNaming
        public void SqlServer_FetchStoredProcedures_RollbackTransaction()
        // ReSharper restore InconsistentNaming
        {
            //------------Setup for test--------------------------
            var factory = new Mock<IDbFactory>();
            var mockCommand = new Mock<IDbCommand>();
            mockCommand.Setup(a => a.CommandText).Returns("Dave.Bob");
            var conn = new Mock<IDbConnection>();
            conn.Setup(a => a.State).Returns(ConnectionState.Open);
            var dbTran = new Mock<IDbTransaction>();
            conn.Setup(a => a.BeginTransaction()).Returns(dbTran.Object);
            factory.Setup(a => a.CreateConnection(It.IsAny<string>())).Returns(conn.Object);
            var sqlServer = new SqlServer(factory.Object);
            try
            {
                PrivateObject pvt = new PrivateObject(sqlServer);
                pvt.SetField("_connection", conn.Object);
                sqlServer.Connect("a");
                sqlServer.BeginTransaction();
                sqlServer.RollbackTransaction();
                factory.Verify(a => a.CreateConnection(It.IsAny<string>()));
                conn.Verify(a => a.Open());

                dbTran.Verify(a => a.Rollback());
                dbTran.Verify(a => a.Dispose());
                conn.Verify(a => a.BeginTransaction());

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

示例8: SqlServer_FetchDatabases_SortedListOfNames

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

            var expected = new List<string>();
            using (var connection = new SqlConnection(dbSource.ConnectionString))
            {
                connection.Open();
                var databases = connection.GetSchema("Databases");
                connection.Close();

                var names = databases.Rows.Cast<DataRow>().Select(row => (row["database_name"] ?? string.Empty).ToString()).Distinct().OrderBy(s => s);
                expected.AddRange(names);
            }

            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                //------------Execute Test---------------------------
                var actual = sqlServer.FetchDatabases();

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

示例9: SqlServer_FetchTableValuedFunctions_AssertSelectTextIsDifferent

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

            List<IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;
            string select = "";
            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.bob")
                    {
                        procedureCommandParameters = list;
                        procedureHelpText = helpText;
                        select = bob;
                    }
                    return true;
                };
                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) => true;

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            Assert.AreEqual("@country", procedureCommandParameters.First().ParameterName);
            Assert.IsTrue(procedureHelpText.Contains(@"insert into @Countries
	select CountryID from dbo.Country"));
            Assert.AreEqual("select * from dbo.bob(@country)", select);
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:39,代码来源:SqlServerTests.cs

示例10: SqlServer_FetchStoredProcedures_WithClrTypeStoredProcedure_CorrectDataReturned

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

            List<IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;

            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "Warewolf.RunWorkflowForSql")
                    {
                        procedureCommandParameters = list;
                        procedureHelpText = helpText;
                    }
                    return true;
                };
                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) => true;

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            SqlServerTestUtils.Verify_FetchStoredProcedures_WarewolfRunForSql(procedureCommandParameters, procedureHelpText);
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:35,代码来源:SqlServerTests.cs

示例11: SqlServer_FetchStoredProcedures_CorrectDataReturned

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

            IDbCommand procedureCommand = null;
            List<IDbDataParameter> procedureCommandParameters = null;
            string procedureHelpText = null;

            IDbCommand functionCommand = null;
            List<IDbDataParameter> functionCommandParameters = null;
            string functionHelpText = null;

            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString);

                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> procedureProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.Pr_CitiesGetCountries")
                    {
                        procedureCommand = dbCommand;
                        procedureCommandParameters = list;
                        procedureHelpText = helpText;
                    }
                    return true;
                };
                Func<IDbCommand, List<IDbDataParameter>, string, string, bool> functionProcessor = (dbCommand, list, helpText, bob) =>
                {
                    if (dbCommand.CommandText == "dbo.fn_Greeting")
                    {
                        functionCommand = dbCommand;
                        functionCommandParameters = list;
                        functionHelpText = helpText;
                    }
                    return true;
                };

                //------------Execute Test---------------------------
                sqlServer.FetchStoredProcedures(procedureProcessor, functionProcessor, true);
            }
            finally
            {
                sqlServer.Dispose();
            }

            //------------Assert Results-------------------------
            SqlServerTestUtils.Verify_FetchStoredProcedures_Pr_CitiesGetCountries(procedureCommand, procedureCommandParameters, procedureHelpText);
            SqlServerTestUtils.Verify_FetchStoredProcedures_Fn_Greeting(functionCommand, functionCommandParameters, functionHelpText);
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:51,代码来源:SqlServerTests.cs

示例12: SqlServer_CreateCommand_TranactionStarted_CommandTransactionIsNotNull

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

            var sqlServer = new SqlServer();
            try
            {
                sqlServer.Connect(dbSource.ConnectionString);
                sqlServer.BeginTransaction();

                //------------Execute Test---------------------------
                var command = sqlServer.CreateCommand();

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

示例13: 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


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