Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

urgent object cannot be cast from dbnull to other types

Posted on 2006-06-23
7
401 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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