﻿# Spending the day coding...(and .NET 1.0.3705.352 bug!)

<datetime class="hidden">2004-02-29T00:00</datetime>
<!-- category -- mostlylucidcouk, Imported, .NET, Database, Software Development -->

I'm working...hmm...thought I'd mention a very odd bug I came across yesterday at
work - which had me puzzled for about a day and a half...

I had written an application (the Portal I've mentioned before - [The
Education Community](http://www.theeducationcommunity.com)), which uses the [Data
Access Application Block](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/daab-rm.asp)to provide the DAL - which I highly recommend. Anyway,
this has always been faultless on every platform I've tried it on. The code is below... 

```
    string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
    string exceptionStr=exception.ToString() + exception.StackTrace;
    SqlParameter[] sqlParams = new SqlParameter[4]; SqlParameter
    prmUser = new SqlParameter("@user",SqlDbType.VarChar,500);
    prmUser.Value = user;
    SqlParameter prmMessage = new SqlParameter("@exceptionMessage",
    SqlDbType.VarChar, 2000);
    prmMessage.Value = exception.Message;
    SqlParameter prmExStr = new SqlParameter("@exception",SqlDbType.Text);
    prmExStr.Value = exceptionStr;
    SqlParameter prmPortalId = new SqlParameter("@portalId",SqlDbType.SmallInt);
    prmPortalId.Value = 0; sqlParams[0] = prmUser;
    sqlParams[1] = prmMessage;
    sqlParams[2] = prmExStr; 
    sqlParams[3] = prmPortalId;
    /*SqlHelperParameterCache.GetSpParameterSet(_connectionString,"pr_Admin_InsertError");  sqlParams[0].Value
    = user;  sqlParams[1].Value = exception.Message;  sqlParams[2].Value
    = exceptionStr;  //sqlParams[2].Value = "Test String";  sqlParams[3].Value
    = ((PortalSettings)HttpContext.Current.Items["PortalSettings"]).PortalId;*/ 
    SqlHelper.ExecuteNonQuery(_connectionString,CommandType.StoredProcedure,"pr_Admin_InsertError",sqlParams);
```

I use a method it provides called SqlHelperParameterCache.GetSpParameters (commented
out in the code above) - this basically just populates an array of SqlParameters with
the parameters returned from the DB - saves a bit of coding and makes the app easier
to update as the SPs change - nice!

Anyway, this has worked faultlessly, fast, efficient all of that! Until that is, I
tried to deploy to our test environment on Thursday - I kept getting various errors,
Severe Error and General Network error back from SQL Server 2000 when I tried to run
the commented code above. Well, the version of .NET on that machine was 1.0.3705.352
- a version I'd never seen and can't get - but I assumed, .NET 1.0 was all pretty
much the same, maybe a few bugfixes but thats' about it!

Umm...wrong, turns out this version has a major issue when you try to get the parameters
back from an SP when the SP expects a 'text' type field - it just gets it wrong somehow
- and causes this awful, puzzling error. Solution, explicitly declare the field types
for the parameters if your SP contains a 'text' field (only one I've tried it for,
may affect more  'binary' types). 

Anyway, fixed now - but I do recommend you upgrade to 1.1 - which also has a fantastic
thing I discovered from some blokes blog at the [ASP.NET
weblogs](http://weblogs.asp.net) simple but saves a bit of typing, seems that DropDownList (I expect
RadioButtonList has it too, but not tried it!) that is a SelectedValue property -
how cool is that - well not that cool, but its' better than doing the old ddl.SelectedItem.Value...bit
shorter...