Esempio n. 1
0
        // Constructors

        protected Driver(CoreServerInfo coreServerInfo, ErrorMessageParser errorMessageParser, bool checkConnectionIsAlive)
            : base(coreServerInfo)
        {
            this.errorMessageParser     = errorMessageParser;
            this.checkConnectionIsAlive = checkConnectionIsAlive;
        }
Esempio n. 2
0
        protected virtual bool TryProvideErrorContext(int errorCode, string errorMessage, SqlExceptionInfo info)
        {
            Dictionary <int, string> parseResult;
            string duplicateValue;

            switch (errorCode)
            {
            case 2627:
                parseResult     = errorMessageParser.Parse(errorCode, errorMessage);
                info.Type       = SqlExceptionType.UniqueConstraintViolation;
                info.Constraint = parseResult[2];
                info.Table      = ErrorMessageParser.CutSchemaPrefix(parseResult[3]);
                if (parseResult.TryGetValue(4, out duplicateValue))
                {
                    info.Value = duplicateValue;
                }
                break;

            case 2601:
                parseResult     = errorMessageParser.Parse(errorCode, errorMessage);
                info.Type       = SqlExceptionType.UniqueConstraintViolation;
                info.Table      = ErrorMessageParser.CutSchemaPrefix(parseResult[1]);
                info.Constraint = parseResult[2];
                if (parseResult.TryGetValue(3, out duplicateValue))
                {
                    info.Value = duplicateValue;
                }
                break;

            case 515:
                parseResult = errorMessageParser.Parse(errorCode, errorMessage);
                info.Type   = SqlExceptionType.CheckConstraintViolation;
                info.Column = parseResult[1];
                info.Table  = ErrorMessageParser.CutDatabaseAndSchemaPrefix(parseResult[2]);
                break;

            case 547:
                parseResult = errorMessageParser.Parse(errorCode, errorMessage);
                switch (parseResult[2])
                {
                case "FOREIGN KEY":
                case "REFERENCE":
                    info.Type = SqlExceptionType.ReferentialConstraintViolation;
                    break;

                case "UNIQUE KEY":
                case "PRIMARY KEY":
                    info.Type = SqlExceptionType.UniqueConstraintViolation;
                    break;

                case "CHECK":
                    info.Type = SqlExceptionType.CheckConstraintViolation;
                    break;

                default:
                    return(false);
                }
                info.Constraint = parseResult[3];
                info.Database   = parseResult[4];
                info.Table      = ErrorMessageParser.CutSchemaPrefix(parseResult[5]);
                info.Column     = ErrorMessageParser.ExtractQuotedText(parseResult[6]);
                break;

            default:
                return(false);
            }
            return(true);
        }
Esempio n. 3
0
        private static SqlDriver CreateDriverInstance(string connectionString, bool isAzure, Version version,
                                                      DefaultSchemaInfo defaultSchema, ErrorMessageParser parser, bool isEnsureAlive)
        {
            var builder        = new SqlConnectionStringBuilder(connectionString);
            var coreServerInfo = new CoreServerInfo {
                ServerVersion            = version,
                ConnectionString         = connectionString,
                MultipleActiveResultSets = builder.MultipleActiveResultSets,
                DatabaseName             = defaultSchema.Database,
                DefaultSchemaName        = defaultSchema.Schema,
            };

            if (isAzure)
            {
                return(new Azure.Driver(coreServerInfo, parser, isEnsureAlive));
            }

            if (version.Major < 9)
            {
                throw new NotSupportedException(Strings.ExSqlServerBelow2005IsNotSupported);
            }
            return(version.Major switch {
                9 => new v09.Driver(coreServerInfo, parser, isEnsureAlive),
                10 => new v10.Driver(coreServerInfo, parser, isEnsureAlive),
                11 => new v11.Driver(coreServerInfo, parser, isEnsureAlive),
                12 => new v12.Driver(coreServerInfo, parser, isEnsureAlive),
                13 => new v13.Driver(coreServerInfo, parser, isEnsureAlive),
                _ => new v13.Driver(coreServerInfo, parser, isEnsureAlive)
            });