Showing posts with label appreciated. Show all posts
Showing posts with label appreciated. Show all posts

Monday, March 26, 2012

Strange DBNULL Error - Please Help!

Dear Group

I'm having a very weird problem. Any hints are greatly appreciated.

I'm returning two values from a MS SQL Server 2000 stored procedure to my
Webapplication and store them in sessions.
Like This:

prm4 = cmd1.CreateParameter
With prm4
..ParameterName = "@dotnet.itags.org.Sec_ProgUser_Gen"
..SqlDbType = SqlDbType.VarChar
..Size = 10
..Direction = ParameterDirection.Output
End With

prm5 = cmd1.CreateParameter
With prm5
..ParameterName = "@dotnet.itags.org.Sec_ProgUser_Key"
..SqlDbType = SqlDbType.VarChar
..Size = 10
..Direction = ParameterDirection.Output
End With
...
cmd1.ExecuteNonQuery()
...
Session("Sec_ProgUser_Gen") = prm4.Value
Session("Sec_ProgUser_Key") = prm5.Value

Both output parameters are declared as varchar(10) within the stored
procedure. If I run the stored procedure in SQL Analyzer, I'm getting a
string value for each of them. E.g. @dotnet.itags.org.Sec_ProgUser_Gen is "1110011",
@dotnet.itags.org.Sec_ProgUser_Key = "1100".

Now the strange thing happens if I try to run the following code:

Sub MyTest()
Dim MyString1 As String
Dim MyString2 As String
MyString1 = CStr(Session("Sec_ProgClient_Key"))
...
MyString2 = CStr(Session("Sec_ProgUser_Gen"))
End Sub

It fails in line 'MyString2 = CStr(Session("Sec_ProgUser_Gen"))' with Cast
from type 'DBNull' to type 'String' is not valid.

I don't understand this. They are both the same, the only difference is the
length of the string. Help!

Additional Information:
The values for @dotnet.itags.org.Sec_ProgUser_XXX are created in the stored procedure with a
statement like this:
SET @dotnet.itags.org.Sec_ProgUser_Key = (SELECT Convert(varchar(1),Key_CanCreateKey) +
Convert(varchar(1),Key_CanCreateTransaction) +
Convert(varchar(1),Key_CanView) + Convert(varchar(1),Key_CanDelete) FROM
i2b_proguser_securityprofile WHERE SecurityProfileID = @dotnet.itags.org.SecurityProfileID)

The datatype of the source columns used to be bit then changed them to
Integer as I thought this might cause the problem. (Although it shouldn't as
the values get converted to varchar without a problem in the stored
procedure. No fields contain NULL values, only 1 or 0.Did you figure this out?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Martin" <theintrepidfox@.hotmail.com> wrote in message
news:7217238c.0401221018.3b36790a@.posting.google.c om...
> Dear Group
> I'm having a very weird problem. Any hints are greatly appreciated.
> I'm returning two values from a MS SQL Server 2000 stored procedure to my
> Webapplication and store them in sessions.
> Like This:
> prm4 = cmd1.CreateParameter
> With prm4
> .ParameterName = "@.Sec_ProgUser_Gen"
> .SqlDbType = SqlDbType.VarChar
> .Size = 10
> .Direction = ParameterDirection.Output
> End With
> prm5 = cmd1.CreateParameter
> With prm5
> .ParameterName = "@.Sec_ProgUser_Key"
> .SqlDbType = SqlDbType.VarChar
> .Size = 10
> .Direction = ParameterDirection.Output
> End With
> ...
> cmd1.ExecuteNonQuery()
> ...
> Session("Sec_ProgUser_Gen") = prm4.Value
> Session("Sec_ProgUser_Key") = prm5.Value
> Both output parameters are declared as varchar(10) within the stored
> procedure. If I run the stored procedure in SQL Analyzer, I'm getting a
> string value for each of them. E.g. @.Sec_ProgUser_Gen is "1110011",
> @.Sec_ProgUser_Key = "1100".
> Now the strange thing happens if I try to run the following code:
> Sub MyTest()
> Dim MyString1 As String
> Dim MyString2 As String
> MyString1 = CStr(Session("Sec_ProgClient_Key"))
> ...
> MyString2 = CStr(Session("Sec_ProgUser_Gen"))
> End Sub
> It fails in line 'MyString2 = CStr(Session("Sec_ProgUser_Gen"))' with Cast
> from type 'DBNull' to type 'String' is not valid.
> I don't understand this. They are both the same, the only difference is
the
> length of the string. Help!
> Additional Information:
> The values for @.Sec_ProgUser_XXX are created in the stored procedure with
a
> statement like this:
> SET @.Sec_ProgUser_Key = (SELECT Convert(varchar(1),Key_CanCreateKey) +
> Convert(varchar(1),Key_CanCreateTransaction) +
> Convert(varchar(1),Key_CanView) + Convert(varchar(1),Key_CanDelete) FROM
> i2b_proguser_securityprofile WHERE SecurityProfileID = @.SecurityProfileID)
> The datatype of the source columns used to be bit then changed them to
> Integer as I thought this might cause the problem. (Although it shouldn't
as
> the values get converted to varchar without a problem in the stored
> procedure. No fields contain NULL values, only 1 or 0.
Hi Alvin

Yes. Thanks for asking. Forgot OUTPUT for @.Sec_ProgUser_Gen

"Alvin Bruney" <vapor at steaming post office> wrote in message news:<OFZOOxs4DHA.1504@.TK2MSFTNGP12.phx.gbl>...
> Did you figure this out?
> --
> Regards,
> Alvin Bruney [ASP.NET MVP]
> Got tidbits? Get it here...
> http://tinyurl.com/3he3b
> "Martin" <theintrepidfox@.hotmail.com> wrote in message
> news:7217238c.0401221018.3b36790a@.posting.google.c om...
> > Dear Group
> > I'm having a very weird problem. Any hints are greatly appreciated.
> > I'm returning two values from a MS SQL Server 2000 stored procedure to my
> > Webapplication and store them in sessions.
> > Like This:
> > prm4 = cmd1.CreateParameter
> > With prm4
> > .ParameterName = "@.Sec_ProgUser_Gen"
> > .SqlDbType = SqlDbType.VarChar
> > .Size = 10
> > .Direction = ParameterDirection.Output
> > End With
> > prm5 = cmd1.CreateParameter
> > With prm5
> > .ParameterName = "@.Sec_ProgUser_Key"
> > .SqlDbType = SqlDbType.VarChar
> > .Size = 10
> > .Direction = ParameterDirection.Output
> > End With
> > ...
> > cmd1.ExecuteNonQuery()
> > ...
> > Session("Sec_ProgUser_Gen") = prm4.Value
> > Session("Sec_ProgUser_Key") = prm5.Value
> > Both output parameters are declared as varchar(10) within the stored
> > procedure. If I run the stored procedure in SQL Analyzer, I'm getting a
> > string value for each of them. E.g. @.Sec_ProgUser_Gen is "1110011",
> > @.Sec_ProgUser_Key = "1100".
> > Now the strange thing happens if I try to run the following code:
> > Sub MyTest()
> > Dim MyString1 As String
> > Dim MyString2 As String
> > MyString1 = CStr(Session("Sec_ProgClient_Key"))
> > ...
> > MyString2 = CStr(Session("Sec_ProgUser_Gen"))
> > End Sub
> > It fails in line 'MyString2 = CStr(Session("Sec_ProgUser_Gen"))' with Cast
> > from type 'DBNull' to type 'String' is not valid.
> > I don't understand this. They are both the same, the only difference is
> the
> > length of the string. Help!
> > Additional Information:
> > The values for @.Sec_ProgUser_XXX are created in the stored procedure with
> a
> > statement like this:
> > SET @.Sec_ProgUser_Key = (SELECT Convert(varchar(1),Key_CanCreateKey) +
> > Convert(varchar(1),Key_CanCreateTransaction) +
> > Convert(varchar(1),Key_CanView) + Convert(varchar(1),Key_CanDelete) FROM
> > i2b_proguser_securityprofile WHERE SecurityProfileID = @.SecurityProfileID)
> > The datatype of the source columns used to be bit then changed them to
> > Integer as I thought this might cause the problem. (Although it shouldn't
> as
> > the values get converted to varchar without a problem in the stored
> > procedure. No fields contain NULL values, only 1 or 0.

Thursday, March 22, 2012

Strange Javascript Cookie Behaviour

Hi folks,

Been looking at this for the day so any ideas would be appreciated. Here's
the scenario, bear with me - it looks more complicated than it is :)

I have a page templating system that inherits from the page class and adds a
mixture of usercontrols and literals when requested.

One of the usercontrols is a menu that expands on being clicked using DHTML.
What I'm trying to do is to persist the expanded menu to other pages or
accross page refreshes so that if a user expands the menu for a menu item on
one page it will be rendered on the following page as expanded for that same
menu item.

As the id of the span needs to be stored when it's clicked I figured that
the easiest way to accomplish this would be to set and pass the id of the
expanded menu item (a <span> element) in a cookie using javascript and then
check for the existence of this cookie and use it's value to expand the menu
using the onLoad attribute of the body tag on the new page.

The cookie is not persisted accross sessions - i.e. no expiry date is set. I
have not set the path either.

At the start of a new session on entering the first page of the site the
function checks the cookie, see's that it doesn't exist yet (as a menu item
hasn't been clicked/expanded yet) and the page simply loads.

On the first page I have established using alert boxes that when I click the
menu item/span the correct id is being being returned to an alert box set to
catch the onclick event and then the cookie is successfully set to the value
of the span id as I use an alert box to return the value of the cookie after
it's set. This works for all menu items.

when I navigate to another page an alert box displaying the cookie value
indicates that the cookie has been successfully persisted and the correct
span is expanded.

However, if I then click on other spans in the menu, the alert box that
displays the id of the span I have clicked returns the correct value and the
span expands, the following line of javascript set's the cookie supposedly
using this span id but in the next line of code producing the second alert
box reading the cookie, the alert box shows that the cookie has been set to
the original span id and not the one I actually clicked. This is confirmed
when I navigate to another page as the original span id is in the cookie and
that span is expanded.

Anyone got any ideas what's going on here???

Looking forward to hearing your ideas,

Bewildered JoeOk, I am officially dumb - it was a path problem - this dumbass takes a bow
;)

"Joe" <info@.hyper-typer.com> wrote in message
news:OykZ3D5uDHA.2880@.tk2msftngp13.phx.gbl...
> Hi folks,
> Been looking at this for the day so any ideas would be appreciated. Here's
> the scenario, bear with me - it looks more complicated than it is :)
> I have a page templating system that inherits from the page class and adds
a
> mixture of usercontrols and literals when requested.
> One of the usercontrols is a menu that expands on being clicked using
DHTML.
> What I'm trying to do is to persist the expanded menu to other pages or
> accross page refreshes so that if a user expands the menu for a menu item
on
> one page it will be rendered on the following page as expanded for that
same
> menu item.
> As the id of the span needs to be stored when it's clicked I figured that
> the easiest way to accomplish this would be to set and pass the id of the
> expanded menu item (a <span> element) in a cookie using javascript and
then
> check for the existence of this cookie and use it's value to expand the
menu
> using the onLoad attribute of the body tag on the new page.
> The cookie is not persisted accross sessions - i.e. no expiry date is set.
I
> have not set the path either.
> At the start of a new session on entering the first page of the site the
> function checks the cookie, see's that it doesn't exist yet (as a menu
item
> hasn't been clicked/expanded yet) and the page simply loads.
> On the first page I have established using alert boxes that when I click
the
> menu item/span the correct id is being being returned to an alert box set
to
> catch the onclick event and then the cookie is successfully set to the
value
> of the span id as I use an alert box to return the value of the cookie
after
> it's set. This works for all menu items.
> when I navigate to another page an alert box displaying the cookie value
> indicates that the cookie has been successfully persisted and the correct
> span is expanded.
> However, if I then click on other spans in the menu, the alert box that
> displays the id of the span I have clicked returns the correct value and
the
> span expands, the following line of javascript set's the cookie supposedly
> using this span id but in the next line of code producing the second alert
> box reading the cookie, the alert box shows that the cookie has been set
to
> the original span id and not the one I actually clicked. This is
confirmed
> when I navigate to another page as the original span id is in the cookie
and
> that span is expanded.
> Anyone got any ideas what's going on here???
> Looking forward to hearing your ideas,
> Bewildered Joe