new to clr Integration,

  • I am creating a small project to read match regex from sql,

    .cs file

    using System;

    using System.Data;

    using System.Data.Sql;

    using System.Data.SqlTypes;

    using Microsoft.SqlServer.Server;

    using System.Collections;

    using System.Text.RegularExpressions;

    public partial class RegExBase

    {

    [SqlFunction(IsDeterministic = true, IsPrecise = true)]

    public static bool RegexSHIP(string matchString, string pattern)

    {

    Regex r1 = new Regex(pattern.TrimEnd(null));

    return Regex.Match(matchString.TrimEnd(null), pattern.TrimEnd(null)).Success;

    }

    };

    Test.sql

    select * from [databasename].[dbo].tablename as P, [databasename].[dbo].tablename as S

    where P.UserID = 'Rep'

    and S.UserID = P.UserID

    and dbo.RegexSHIP('T_SHIP_123456.txt', S.Pattern) = 1

    I have enable clr, created function but still getting the attach error and help to solve that.

    Thanks

  • the error message is related to debugging.

    do you really need to debug the CLR?

    why not just deploy the project, then test it in q window for known pattern/values?

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • do you really need to debug the CLR? No

    All I want is to test it.

    why not just deploy the project, then test it in q window for known pattern/values?

    everything run fine except I don't get any output.

  • I think I solved my issue, it was from my data it needed some clean up

  • Slightly off subject, it's been reported that some forms of Regex CLR are quite slow. If it does turn out to be one of the slow ones, it won't look slow on just a couple of rows but could take quite some time if you're batch processing several thousand rows.

    To be sure, I'm not in any way shape or form saying to avoid CLRs. I'm saying the same as I would for any type of code where there was a known issue including T-SQL and to simply be aware of it.

    The question that I would have is what are you doing in RegEx that a more simple LIKE or other pattern matching in T-SQL can't do for you? The reason why I'm asking that is because if you are using Regex to replace the simple pattern matching that you can do in T-SQL, there's a very high probability that functionality will be a fair bit slower than the equivalent T-SQL code.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply