Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Odd Behvavior When Storing Binary Strings in DBOdd Behvavior When Storing Binary Strings in DB
Previous
 
Next
New Post
11/14/2009 7:13 PM
 

All,

What I'm trying to do is store a binary array (byte[]) in the database in a varbinary field.

When I insert a binary string that's 16 bytes long it works fine; however, if I try to insert a binary string of length 24 bytes then it only stores 16 bytes despite how big I make the varbinary fields in the table as well as the parameter to the stored procedure which does the insert.  I double and triple checked all the field lengths (in the table as well as the stored procedure).  

My guess is that something is happening inside of the SqlHelper.ExecuteNonQuery function that's somehow forcing any byte arrays of greater than 16 bytes to be exactly 16 bytes. 

Any help would be greatly appreciated.

Jeremy

 
New Post
11/16/2009 4:03 PM
 

Are you using strongly typed parameters when you are making the call out to SqlHelper?  Can you show us the call as you have it constructed.


-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
11/17/2009 5:22 AM
 

Hi

I don't think it's fault of SqlHelper.ExecuteNonQuery.

How do you generate binary array? check this array first .. is it coming perfectly?

Sahil

 
New Post
11/17/2009 10:20 PM
 

Hey,

Here's what I did to work around the problem and why I think it is the fault of the SqlHelper function:

 

The first code snippet is the original function using the SqlHelper and the second function is what I did to work around the problem

The version that didn't work:

public override void AddPaymentInfo(int portalID, int userID, int orderID, byte[] creditCardNumber, byte[] creditCardVerificationCode,
            byte[] creditCardExpirationMonth, byte[] creditCardExpirationYear)
        {
            SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "Store_PaymentInfo_AddPaymentInfo",
                portalID,orderID,userID,creditCardNumber,creditCardVerificationCode,creditCardExpirationMonth,creditCardExpirationYear);
        }

 

The version that worked:

public override void AddPaymentInfo(int portalID, int userID, int orderID, byte[] creditCardNumber, byte[] creditCardVerificationCode,
            byte[] creditCardExpirationMonth, byte[] creditCardExpirationYear)
        {
            SqlConnection connection = new SqlConnection(ConnectionString);
            connection.Open();

            string commandText = DatabaseOwner + ObjectQualifier + "Store_PaymentInfo_AddPaymentInfo";

            SqlCommand command = new SqlCommand(commandText, connection);
            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.AddWithValue("PortalID",portalID);
            command.Parameters.AddWithValue("UserID", userID);
            command.Parameters.AddWithValue("OrderID", orderID);
            command.Parameters.AddWithValue("CreditCardNumber", creditCardNumber);
            command.Parameters.AddWithValue("CreditCardVerificationCode", creditCardVerificationCode);
            command.Parameters.AddWithValue("CreditCardExpirationMonth", creditCardExpirationMonth);
            command.Parameters.AddWithValue("CreditCardExpirationYear", creditCardExpirationYear);

            //SqlHelper.ExecuteNonQuery(ConnectionString, DatabaseOwner + ObjectQualifier + "Store_PaymentInfo_AddPaymentInfo",
            //    portalID,orderID,userID,creditCardNumber,creditCardVerificationCode,creditCardExpirationMonth,creditCardExpirationYear);
            command.ExecuteNonQuery();

            connection.Close();
        }

 
New Post
11/19/2009 2:43 AM
Accepted Answer 

Hi miller,

SqlHelper.ExecuteNonQuery() has many overload, the overload which you are using has good flexibility but interanlly it's using SqlCommandBuilder for extracting Sp para and than execute SP. So we can say it 's 2 round trip at one call.

And as you mentioned Second bolck of code is working you can use one the overload of SqlHelper.ExecuteNonQuery() having "SqlParameter[]" as a argument

so no need to write manual code for SQL trans.

Hope this i'll help you.

 

Sahilmohammad

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Odd Behvavior When Storing Binary Strings in DBOdd Behvavior When Storing Binary Strings in DB


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out