trouble with ADODB in C#

J

jason

hello everyone. i am using ADODB in a C# class library. why? because
one of the applications using the class library is written in classic
ASP, and therefore can't be handed an ADO.NET DataReader class and know
what to do with it.

no problem, ADODB in C# lets me generate a class RecordSet object to
hand to the ASP classic application without trouble in most cases.
however, this is one of the problem cases:

i originally had the following code in a C# method:

// INT VERSION
// AuthorityID was a public int property
// nUserID was an argument supplied in the method call
oCommand.Parameters.Append(
oCommand.CreateParameter("@aut­horityid",
ADODB.DataTypeEnum.adInteger,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(AuthorityID),
AuthorityID));
oCommand.Parameters.Append(
oCommand.CreateParameter("@use­rid", ADODB.DataTypeEnum.adInteger,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(nUserID),
nUserID));

this code worked fine, and generated the desired recordset when
executed. however, the datatype of the column (and therefore the stored
procedure parameter) changed from an int to a guid. this meant the
following code change:

// GUID VERSION
Guid gUserID = new Guid(sUserID);
Guid gAuthorityID = new Guid(AuthorityID);
oCommand.Parameters.Append(
oCommand.CreateParameter("@aut­horityid",
ADODB.DataTypeEnum.adGUID,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(gAuthorityID),
gAuthorityID));
oCommand.Parameters.Append(
oCommand.CreateParameter("@use­rid", ADODB.DataTypeEnum.adGUID,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(gUserID),
gUserID));


the old code worked just fine, but the new code generates a Stack
Overflow error. i tried putting the two methods in a try / catch block,
but it failed to cause an actual exception, so I'm not sure what
exactly is causing the overflow in the GUID version. Any ideas? Is it
that .NET GUID class doesn't play well with the ADO objects?

i've tried different sizes for the guid parameters as well. such as the
static 16 bytes that a guid should be. a whopping 200 bytes just to
make sure it wasn't too small. zero bytes to see if that would cause
ADODB to auto-size. all of these things generated the overflow.

any help would be greatly appreciated!

jason


Any help is appreciated,
 
N

Nicholas Paldino [.NET/C# MVP]

Jason,

I believe it's because the provider doesn't know what the System.Guid
type is. Instead of passing the value itself, change it into a string
(without the brackets) and pass that as the value. The provider should be
able to parse it apart properly and send the proper representation.

Also, you shouldn't be setting the size based on the unmanaged size on
the client. While it is the same most of the time, for fixed size types
like this, it is ignored, and additionally, it might not always be the same.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

hello everyone. i am using ADODB in a C# class library. why? because
one of the applications using the class library is written in classic
ASP, and therefore can't be handed an ADO.NET DataReader class and know
what to do with it.

no problem, ADODB in C# lets me generate a class RecordSet object to
hand to the ASP classic application without trouble in most cases.
however, this is one of the problem cases:

i originally had the following code in a C# method:

// INT VERSION
// AuthorityID was a public int property
// nUserID was an argument supplied in the method call
oCommand.Parameters.Append(
oCommand.CreateParameter("@aut­horityid",
ADODB.DataTypeEnum.adInteger,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(AuthorityID),
AuthorityID));
oCommand.Parameters.Append(
oCommand.CreateParameter("@use­rid", ADODB.DataTypeEnum.adInteger,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(nUserID),
nUserID));

this code worked fine, and generated the desired recordset when
executed. however, the datatype of the column (and therefore the stored
procedure parameter) changed from an int to a guid. this meant the
following code change:

// GUID VERSION
Guid gUserID = new Guid(sUserID);
Guid gAuthorityID = new Guid(AuthorityID);
oCommand.Parameters.Append(
oCommand.CreateParameter("@aut­horityid",
ADODB.DataTypeEnum.adGUID,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(gAuthorityID),
gAuthorityID));
oCommand.Parameters.Append(
oCommand.CreateParameter("@use­rid", ADODB.DataTypeEnum.adGUID,
ADODB.ParameterDirectionEnum.a­dParamInput,
System.Runtime.InteropServices­.Marshal.SizeOf(gUserID),
gUserID));


the old code worked just fine, but the new code generates a Stack
Overflow error. i tried putting the two methods in a try / catch block,
but it failed to cause an actual exception, so I'm not sure what
exactly is causing the overflow in the GUID version. Any ideas? Is it
that .NET GUID class doesn't play well with the ADO objects?

i've tried different sizes for the guid parameters as well. such as the
static 16 bytes that a guid should be. a whopping 200 bytes just to
make sure it wasn't too small. zero bytes to see if that would cause
ADODB to auto-size. all of these things generated the overflow.

any help would be greatly appreciated!

jason


Any help is appreciated,
 
J

jason

thanks for the tip! i think i started out trying the string version of
the guid, but perhaps i wasn't getting it into a recognizable format. i
will try it again!

jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top