Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

C# CLR UDF Deploy errors.

$
0
0

Hi,

I am trying to create a simple CLR UDF address parser.  The code builds with no errors, however when I deploy I get a

"Deploy error SQL01268. .Net SqlClient Data Provider: Msg 6208, Level 16, State 1, Procedure AddyParser, Line 1 CREATE FUNCTION failed because the parameter count for the FillRow method should be one more than the SQL declaration for the table valued CLR function. "

I am not finding anything out on the interwebs about this specifically.  If anyone could clarify this for me, that would be awesome.

using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Text.RegularExpressions; using System.Collections; public partial class UserDefinedFunctions { private class AddyResult { public SqlString strStreetNumRe; public SqlString strPreDirRe; public SqlString strStreetNameRe; public SqlString strPostDirRe; public SqlString strUnitNumRe; public SqlString strUnitNameRe; public SqlString strBoxNumRe; public SqlString strBoxNameRe; public AddyResult(SqlString strStreetNum, SqlString strPreDir, SqlString strStreetName, SqlString strPostDir, SqlString strUnitNum, SqlString strUnitName, SqlString strBoxNum, SqlString strBoxName) { strStreetNumRe = strStreetNum; strPreDirRe = strPreDir; strStreetNameRe = strStreetName; strPostDirRe = strPostDir; strUnitNumRe = strUnitNum; strUnitNameRe = strUnitName; strBoxNumRe = strBoxNum; strBoxNameRe = strBoxName; } } public static void TableUDF_FillRow(ref SqlString streetnum, ref SqlString predir, ref SqlString streetnam, ref SqlString postdir, ref SqlString unitnum, ref SqlString unitnam, ref SqlString boxnum, ref SqlString boxnam) { var addyResult = new AddyResult(streetnum, predir, streetnam, postdir, unitnum, unitnam, boxnum, boxnam); streetnum = addyResult.strStreetNameRe; predir = addyResult.strPreDirRe; streetnam = addyResult.strStreetNameRe; postdir = addyResult.strPostDirRe; unitnum = addyResult.strUnitNumRe; unitnam = addyResult.strUnitNameRe; boxnum = addyResult.strBoxNameRe; boxnam = addyResult.strBoxNameRe; } //[Microsoft.SqlServer.Server.SqlFunction] [SqlFunction( DataAccess = DataAccessKind.Read, TableDefinition = "strStreetNumRe NVARCHAR(256),strPreDirRe NVARCHAR(256),strStreetNameRe NVARCHAR(256), strPostDirRe NVARCHAR(256), strUnitNumRe NVARCHAR(256), strUnitNameRe NVARCHAR(256), strBoxNumRe NVARCHAR(256), strBoxNameRe NVARCHAR(256)", FillRowMethodName = "TableUDF_FillRow")] public static IEnumerable AddyParser(String OrigAddress1, String OrigAddress2) { string strStreetNum = ""; string strPreDir = ""; string strStreetName = ""; string strPostDir = ""; string strUnitNum = ""; string strUnitName = ""; string strBoxNum = ""; string strBoxName = ""; String AddyToParse = OrigAddress1; String pattern = "#"; String replacement = "# "; Regex rgx = new Regex(pattern); String CleanedStr; String AddyToParse2 = OrigAddress2; CleanedStr = rgx.Replace(AddyToParse, replacement); pattern = "\\s+"; CleanedStr = rgx.Replace(AddyToParse, replacement); pattern = ","; rgx = new Regex(pattern); CleanedStr = rgx.Replace(AddyToParse, replacement); CleanedStr = rgx.Replace(AddyToParse, replacement); pattern = "."; rgx = new Regex(pattern); CleanedStr = rgx.Replace(AddyToParse, replacement); //Split String on spaces string[] words = CleanedStr.Split(' '); //Count number of words in string int cnt = words.Length; strStreetNum = words[0]; strPreDir = words[1] strStreetName = words[2]; strPostDir = words[3]; strUnitNum = words[4]; strUnitName = words[5]; strBoxNum = words[6]; strBoxName = words[7]; var tableResults = new ArrayList { new AddyResult(strStreetNum, strPreDir, strStreetName, strPostDir, strUnitNum, strUnitName, strBoxNum, strBoxName) {strStreetNumRe = strStreetNum, strPreDirRe = strPreDir, strStreetNameRe = strStreetName, strPostDirRe = strPostDir, strUnitNumRe = strUnitNum, strUnitNameRe = strUnitName, strBoxNumRe = strBoxNum, strBoxNameRe = strBoxName} }; return tableResults; } //End of AddyParser } //End of UserDefinedFunction




Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>