public void ConnectThrowsExceptionIfAlreadyConnected() { const string anyConnectionStringWillDo = "x"; var driver = new Mock<IOdbcDriver>(); using (var environmentHandle = new OdbcEnvironmentHandle(OdbcVersion.Version38, OdbcConnectionPooling.None, driver.Object)) { using (IOdbcConnection sut = new OdbcConnectionHandle(environmentHandle, driver.Object)) { sut.SetPrivateFieldValue("_connected", true); var bc = sut; try { TestHelper.AssertThrows<InvalidOperationException>(() => bc.Connect(anyConnectionStringWillDo)); } finally { sut.SetPrivateFieldValue("_connected", false); } } } }
internal static IntPtr AllocateConnectionHandle(OdbcEnvironmentHandle environmentHandle) { if (environmentHandle == null) throw new ArgumentNullException("environmentHandle"); IntPtr handle; var result = NativeMethods.SQLAllocHandle(OdbcHandleType.Connection, environmentHandle, out handle); if ((result == OdbcReturnCode.Success) || (result == OdbcReturnCode.SuccessWithInfo)) return handle; var ex = GetException(environmentHandle, "Unable to allocate ODBC connection handle."); throw ex; }
public void ConnectThrowsExceptionWhenTableNameIsNullOrEmpty() { var driver = new Mock<IOdbcDriver>(); using (var environmentHandle = new OdbcEnvironmentHandle(OdbcVersion.Version38, OdbcConnectionPooling.None, driver.Object)) { using (IOdbcConnection sut = new OdbcConnectionHandle(environmentHandle, driver.Object)) { var bc = sut; TestHelper.AssertThrows<ArgumentException>(() => bc.Connect(null)); TestHelper.AssertThrows<ArgumentException>(() => bc.Connect(string.Empty)); } } }
internal static extern OdbcReturnCode SQLSetEnvAttr(OdbcEnvironmentHandle environmentHandle, OdbcEnvironmentAttribute attribute, int value, int valueLengthShouldBeZero);
internal static extern OdbcReturnCode SQLAllocHandle(OdbcHandleType handleType, OdbcEnvironmentHandle inputHandle, out IntPtr outputHandle);
internal static void SetIntEnvironmentAttribute(OdbcEnvironmentHandle environmentHandle, OdbcEnvironmentAttribute attribute, int value) { if (environmentHandle == null) throw new ArgumentNullException("environmentHandle"); var result = NativeMethods.SQLSetEnvAttr(environmentHandle, attribute, value, 0); if ((result != OdbcReturnCode.Success) && (result != OdbcReturnCode.SuccessWithInfo)) { var ex = GetException(environmentHandle, string.Format("Unable to set ODBC environment attribute '{0:G}'.", attribute)); throw ex; } }
public void ConstructorThrowsExceptionWhenDriverIsNull() { var driver = new Mock<IOdbcDriver>(); using (var environmentHandle = new OdbcEnvironmentHandle(OdbcVersion.Version38, OdbcConnectionPooling.None, driver.Object)) { var sut = new OdbcConnectionHandle(environmentHandle, null); } }