SQL Server 2000 error and .NET error deciphering

By awildes ·
Hey all,

I have an application that gives the following error upon login:

System.InvalidCastException: Cast from type 'Guid' to type
'String' is not valid.

Without going into detail about the application, can someone give me a generic meaning of this error message? It appears that as long as SQL Server 2000 replication is turned off there is no issue. Any and all help would be greatly appreciated.

Thanks in advance
Alex Wildes

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

SQL Server 2000 error and .NET error deciphering

by navyjax2 In reply to SQL Server 2000 error and ...

Probably means you're trying to retrieve a "uniqueidentifier" type, or GUID, from a database using ExecuteScalar() and are casting it to a string type, like this:

sqlCommand sqlCmd = new SqlCommand("SELECT min(Table_Id) FROM Table1", sqlConn);
string myGuid = (string)sqlCmd.ExecuteScalar();

where Table_Id is a column of GUIDs.

Problem is that you can't cast a GUID as a string when retrieving it - has to be of GUID type.


Related Discussions

Related Forums