?
Solved

urgent object cannot be cast from dbnull to other types

Posted on 2006-06-23
7
Medium Priority
?
421 Views
Last Modified: 2008-02-20
hi all ,
i a have a situation when tested in qa it workerd fine cause there were no linked servers involved but whern it is realsed in production it starts showing this error object cannot be cast from dbnull to other types in a part where i want to retrun an identity column using select scope_identity() or Select @@identity in my stored procs.
0
Comment
Question by:jemigossaye
  • 4
  • 3
7 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 16969344
Both those can return null if there hasn't been an identity generated on the current connection.  Presumably, you are casting the return value into an int in your c# - which leads to the cast error as an int can't be null.
0
 

Author Comment

by:jemigossaye
ID: 16969453
the idenitity is being generated and inseretd in the table the thing is select scope idntity or @@identity doesn't work with remote servers and my storedprocs are in local server and the data is inserted in to a thired  party server which don't have any access to except to store data. i am looking for a work arround for this cause i have no idea what to do


thanks
0
 
LVL 21

Expert Comment

by:mastoo
ID: 16969620
Ah, I missed the mention of linked server.  I've seen other people having this problem.  There's an ugly unreliable work-around, but the real fix is to do the sql in a proc executed on the remote server and return identity as an output parameter.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:jemigossaye
ID: 16969694
can you please show an example or a fragment code

thanks
0
 
LVL 21

Expert Comment

by:mastoo
ID: 16970132
There might be an easier way, but basically...

Your remote proc looks like this:

create procedure myremoteproc( @input1 int, @myid int output )
begin

  insert into sometbl( name1 ) values ( @input1 )
  select @myid = scope_identity()

end

I think you can run this directly from code using something like this from c#:

[LINKEDSERVER].database.owner.myproc

and the input and output parameters (the output will be your identity) in the usual c# fashion.
0
 

Author Comment

by:jemigossaye
ID: 16984409
Hello,

I still need help casue the remote server is a third party server and  they are not letting us do a single thing on that remote server  

Can anybody tell or rather HELP ME on another way to solve this
0
 
LVL 21

Accepted Solution

by:
mastoo earned 2000 total points
ID: 16985150
If there are some other values inserted that are unique, you could query for the id based on those values.  Otherwise, you're left with something ugly like querying for the last ident on that table or max value, both of which might be somebody else's record inserted shortly after yours.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month15 days, 12 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question