Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 Issue WIth Assembly Based Procedure

Author  Topic 

SilentCodingOne
Starting Member

20 Posts

Posted - 2008-12-28 : 23:27:32
I have a homework problem that requires me to create a procedure that uses a dll assembly. The procedure is suppose to return environment values. The following is my procedure:


CREATE PROC dbo.usp_GetEnvInfo
(
@envProperty NVARCHAR(20),
@machineName NVARCHAR(256),
@processors VARCHAR(255),
@osVersion VARCHAR(255),
@clrVersion VARCHAR(255)
)
AS EXTERNAL NAME uspGetEnvInfo.StoredProcedures.usp_GetEnvInfo


Here is the assembly code:


using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Text.RegularExpressions;
using System.Globalization;

public partial class StoredProcedures
{
// Stored procedure that returns environment info in tabular format
[Microsoft.SqlServer.Server.SqlProcedure]
public static void usp_GetEnvInfo()
{
// Create a record - object representation of a row
// Include the metadata for the SQL table
SqlDataRecord record = new SqlDataRecord(
new SqlMetaData("EnvProperty", SqlDbType.NVarChar, 20),
new SqlMetaData("Value", SqlDbType.NVarChar, 256));
// Marks the beginning of the result set to be sent back to the client
// The record parameter is used to construct the metadata
// for the result set
SqlContext.Pipe.SendResultsStart(record);
// Populate some records and send them through the pipe
record.SetSqlString(0, @"Machine Name");
record.SetSqlString(1, Environment.MachineName);
SqlContext.Pipe.SendResultsRow(record);
record.SetSqlString(0, @"Processors");
record.SetSqlString(1, Environment.ProcessorCount.ToString());
SqlContext.Pipe.SendResultsRow(record);
record.SetSqlString(0, @"OS Version");
record.SetSqlString(1, Environment.OSVersion.ToString());
SqlContext.Pipe.SendResultsRow(record);
record.SetSqlString(0, @"CLR Version");
record.SetSqlString(1, Environment.Version.ToString());
SqlContext.Pipe.SendResultsRow(record);
// End of result set
SqlContext.Pipe.SendResultsEnd();
}
};


The problem I'm having is that whenever I try to create the procedure I get the following error:

Msg 6550, Level 16, State 2, Procedure usp_GetEnvInfo, Line 1
CREATE PROCEDURE failed because parameter counts do not match.

I was hoping someone could help me figure out what I need to make the procedure work.

Thanks

SilentCodingOne
Starting Member

20 Posts

Posted - 2008-12-30 : 00:03:10
I was able to figure this one out. I was making it alot harder than it needed to be as the code to create the procedure ended up being:


CREATE PROC dbo.usp_GetEnvInfo
AS EXTERNAL NAME uspGetEnvInfo.StoredProcedures.usp_GetEnvInfo


When this procedure is run the various pieces of the system environment variables are pulled.
Go to Top of Page
   

- Advertisement -