Question Locked

SQL Server 2000 error and .NET error deciphering

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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
Always
Alex Wildes
MCITP:SQL SERVER 2005 DBA

2 replies

by navyjax2

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.

-Tom

This discussion is closed to new replies.