Example #1
0
        private static IsolationLevel MapOdbcIsolationLevel(OdbcIsolationLevel odbcLevel)
        {
            IsolationLevel isoLevel = IsolationLevel.Unspecified;

            switch (odbcLevel)
            {
            case OdbcIsolationLevel.ReadUncommitted:
                isoLevel = IsolationLevel.ReadUncommitted;
                break;

            case OdbcIsolationLevel.ReadCommitted:
                isoLevel = IsolationLevel.ReadCommitted;
                break;

            case OdbcIsolationLevel.RepeatableRead:
                isoLevel = IsolationLevel.RepeatableRead;
                break;

            case OdbcIsolationLevel.Serializable:
                isoLevel = IsolationLevel.Serializable;
                break;

            case OdbcIsolationLevel.Snapshot:
                isoLevel = IsolationLevel.Snapshot;
                break;
            }
            return(isoLevel);
        }
Example #2
0
        private static IsolationLevel MapOdbcIsolationLevel(OdbcIsolationLevel odbcLevel)
        {
            IsolationLevel isoLevel = IsolationLevel.Unspecified;

            switch (odbcLevel)
            {
            case OdbcIsolationLevel.ReadUncommitted:
                isoLevel = IsolationLevel.ReadUncommitted;
                break;

            case OdbcIsolationLevel.ReadCommitted:
                isoLevel = IsolationLevel.ReadCommitted;
                break;

            case OdbcIsolationLevel.RepeatableRead:
                isoLevel = IsolationLevel.RepeatableRead;
                break;

            case OdbcIsolationLevel.Serializable:
                isoLevel = IsolationLevel.Serializable;
                break;

#if NET_2_0
            case OdbcIsolationLevel.Snapshot:
                isoLevel = IsolationLevel.Snapshot;
                break;
#else
            default:
                throw new NotSupportedException(string.Format(
                                                    CultureInfo.InvariantCulture,
                                                    "Isolation level {0} is not supported.",
                                                    odbcLevel));
#endif
            }
            return(isoLevel);
        }
Example #3
0
		private static IsolationLevel MapOdbcIsolationLevel (OdbcIsolationLevel odbcLevel)
		{
			IsolationLevel isoLevel = IsolationLevel.Unspecified;

			switch (odbcLevel) {
			case OdbcIsolationLevel.ReadUncommitted:
				isoLevel = IsolationLevel.ReadUncommitted;
				break;
			case OdbcIsolationLevel.ReadCommitted:
				isoLevel = IsolationLevel.ReadCommitted;
				break;
			case OdbcIsolationLevel.RepeatableRead:
				isoLevel = IsolationLevel.RepeatableRead;
				break;
			case OdbcIsolationLevel.Serializable:
				isoLevel = IsolationLevel.Serializable;
				break;
			case OdbcIsolationLevel.Snapshot:
				isoLevel = IsolationLevel.Snapshot;
				break;
			}
			return isoLevel;
		}
Example #4
0
        internal OdbcTransaction(OdbcConnection conn, IsolationLevel isolationlevel)
        {
            // Set Auto-commit (102) to false
            SetAutoCommit(conn, false);
            // Handle isolation level
            OdbcIsolationLevel      lev  = OdbcIsolationLevel.ReadCommitted;
            OdbcConnectionAttribute attr = OdbcConnectionAttribute.TransactionIsolation;

            switch (isolationlevel)
            {
            case IsolationLevel.ReadUncommitted:
                lev = OdbcIsolationLevel.ReadUncommitted;
                break;

            case IsolationLevel.ReadCommitted:
                lev = OdbcIsolationLevel.ReadCommitted;
                break;

            case IsolationLevel.RepeatableRead:
                lev = OdbcIsolationLevel.RepeatableRead;
                break;

            case IsolationLevel.Serializable:
                lev = OdbcIsolationLevel.Serializable;
                break;

            case IsolationLevel.Snapshot:
                // badly broken on MS:
                // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=305736
                lev = OdbcIsolationLevel.Snapshot;

                // SQL_ATTR_TXN_ISOLATION can be used to set all other isolation
                // levels except for SQL_TXN_SS_SNAPSHOT. If you want to use snapshot
                // isolation, you must set SQL_TXN_SS_SNAPSHOT through
                // SQL_COPT_SS_TXN_ISOLATION. However, you can retrieve the
                // isolation level by using either SQL_ATTR_TXN_ISOLATION or
                // SQL_COPT_SS_TXN_ISOLATION.
                // Source:
                // http://msdn2.microsoft.com/en-us/library/ms131709.aspx
                attr = OdbcConnectionAttribute.CoptTransactionIsolation;
                break;

            case IsolationLevel.Unspecified:
                // when isolationlevel is not specified, then use
                // default isolation level of the driver and
                // lazy initialize it in the IsolationLevel property
                break;

            case IsolationLevel.Chaos:
                throw new ArgumentOutOfRangeException("IsolationLevel",
                                                      string.Format(CultureInfo.CurrentCulture,
                                                                    "The IsolationLevel enumeration " +
                                                                    "value, {0}, is not supported by " +
                                                                    "the .Net Framework Odbc Data " +
                                                                    "Provider.", (int)isolationlevel));

            default:
                throw new ArgumentOutOfRangeException("IsolationLevel",
                                                      string.Format(CultureInfo.CurrentCulture,
                                                                    "The IsolationLevel enumeration value, {0}, is invalid.",
                                                                    (int)isolationlevel));
            }

            // only change isolation level if it was explictly set
            if (isolationlevel != IsolationLevel.Unspecified)
            {
                // mbd: Getting the return code of the second call to SQLSetConnectAttr is missing from original code!
                OdbcReturn ret = libodbc.SQLSetConnectAttr(conn.hDbc,
                                                           attr, (IntPtr)lev, 0);
                if (ret != OdbcReturn.Success && ret != OdbcReturn.SuccessWithInfo)
                {
                    throw conn.CreateOdbcException(OdbcHandleType.Dbc, conn.hDbc);
                }
            }
            this.isolationlevel = isolationlevel;
            connection          = conn;
            isOpen = true;
        }
Example #5
0
		private static IsolationLevel MapOdbcIsolationLevel (OdbcIsolationLevel odbcLevel)
		{
			IsolationLevel isoLevel = IsolationLevel.Unspecified;

			switch (odbcLevel) {
			case OdbcIsolationLevel.ReadUncommitted:
				isoLevel = IsolationLevel.ReadUncommitted;
				break;
			case OdbcIsolationLevel.ReadCommitted:
				isoLevel = IsolationLevel.ReadCommitted;
				break;
			case OdbcIsolationLevel.RepeatableRead:
				isoLevel = IsolationLevel.RepeatableRead;
				break;
			case OdbcIsolationLevel.Serializable:
				isoLevel = IsolationLevel.Serializable;
				break;
#if NET_2_0
			case OdbcIsolationLevel.Snapshot:
				isoLevel = IsolationLevel.Snapshot;
				break;
#else
			default:
				throw new NotSupportedException (string.Format (
					CultureInfo.InvariantCulture,
					"Isolation level {0} is not supported.",
					odbcLevel));
#endif
			}
			return isoLevel;
		}