PROCEDURES So, in general, when you are writing

PROCEDURES So, in general, when you are writing methods to be used to implement procedures and functions, it is important to always check whether an instance of SqlType you are using is representing a null. The following code is a corrected version of the PassCharsmethod that does this. namespace Procedures { public class Parameters { // SqlString is used as the type for str // because it matches the nchar type // listed in Table 3-1 public static int PassChars(SqlString str) { // test for null if(str.IsNull) { // return a 0 just like the PassCharsTSql does return 0; } // the T-SQL LEN function trims trailing // spaces in the string, so you must too return str.Value.TrimEnd().Length; } } } The return value of the method used to implement the procedure will be the return code for that procedure. The return type for the method may be void, SqlInt32, SqlInt16, Int32, or Int16. If void is used, the procedure will always have a return code of 0. Once you have written a CLR method for a procedure, you must compile it and catalog its assembly, as was shown in Chapter 2. The following script can be run on the command line to compile and catalog the assembly shown earlier, which we will assume is in a file named procedures.cs. It will add this to a local database named Chapter3. Note that sqlcmd is a utility included with SQL Server 2005 that allows a SQL expression to be executed from the command line. csc /target:library procedures.cs sqlcmd d Chapter3 Q CREATE ASSEMBLY procedures FROM %CD%procedures.dll with PERMISSION_SET = SAFE The sqlcmd line has been wrapped to fit onto the page. Also note that %CD% will be expanded by the command shell to the current directory, which is where the assembly produced by cscwill be.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost PHP Web Hosting services

Bookmark the permalink.

Comments are closed.