This is a migrated thread and some comments may be shown as answers.

System.InvalidOperationException: Wrong type System.Guid

7 Answers 226 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
dhaval
Top achievements
Rank 1
dhaval asked on 26 Apr 2011, 09:03 PM
Hello,

I have downloaded new version of ORM and have upgrade project from 2009.3.1119.2 version to 2011.1.411.2

I am facing some problem of accessing a stored procedure of having datatype Guid (uniqueidentifier ), it is giving following error

{"System.InvalidOperationException: Wrong type System.Guid\r\n   at OpenAccessRuntime.Data.CommonNumberConverter.ReadIntegralValue(DbDataReader r, Int32 pos, Type t)\r\n   at OpenAccessRuntime.Data.IntConverter.Read(DataHolder& data)\r\n   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.FetchToObjectArray(ResultSet rs, MappingInfo mi)\r\n   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.fetch(FetchResult fetchResult, StateContainer stateContainer)\r\n   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)\nProcessing 0:  System.InvalidOperationException: Wrong type System.Guid\r\n   at OpenAccessRuntime.Data.CommonNumberConverter.ReadIntegralValue(DbDataReader r, Int32 pos, Type t)\r\n   at OpenAccessRuntime.Data.IntConverter.Read(DataHolder& data)\r\n   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.FetchToObjectArray(ResultSet rs, MappingInfo mi)\r\n   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.fetch(FetchResult fetchResult, StateContainer stateContainer)\r\n   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)"}

can you guide me what could be the problem?

Thanks in advance

7 Answers, 1 is accepted

Sort by
0
Ady
Telerik team
answered on 02 May 2011, 02:29 PM
Hello dhaval,

 Can you provide some more information like which backend are you using, and how do you get this exception? Are you trying to execute the stored procedure using the generated method on the context class? Can you provide some steps to reproduce this exception?

Greetings,
Ady
the Telerik team
Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
0
dhaval
Top achievements
Rank 1
answered on 06 May 2011, 03:50 PM
Hello Ady,

Please find full details here with, we have used MSSQLServer 2008 R2 as a backend.

*********************************Error Message*****************************

-------------------------ntTrace-----------------

   at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
   at Telerik.OpenAccess.RT.ExceptionWrapper.Throw()
   at OpenAccessRuntime.storagemanager.logging.LoggingStorageManager.executeQueryAll(ApplicationContext context, ImmutableQueryDetails query, CompiledQuery compiledQuery, QueryParameters parameters, Int32 skip, Int32 take)
   at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.getAllQueryResults(CompiledQuery cq, QueryParameters parameters, Int32 skip, Int32 take)
   at OpenAccessRuntime.DataObjects.ForwardQueryResult.Resolve()
   at OpenAccessRuntime.DataObjects.ForwardQueryResult.get_Count()
   at Telerik.OpenAccess.RT.ListEnumerator.get_Count()
   at DBLibrary.StoredProcedure.PrGetVcancyDetaillForSelectedJob(IObjectScope scope, String vacancyID, Guid contactID, Int16 pageMode) in C:\Inetpub\wwwroot\CRPortal\DBLibrary\StoredProcedure.vb:line 500
   at DBLibrary.CommonMethod.GetSelectedVacancy_Detail(String StrVacancyID, Guid ContactID, Int32 PageMode) in C:\Inetpub\wwwroot\CRPortal\DBLibrary\UserDefineClasses\CommonMethods.vb:line 2394


----------------------ntMessage---------------------

System.InvalidCastException: Specified cast is not valid.
   at System.Data.SqlClient.SqlBuffer.get_SqlGuid()
   at System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i)
   at OpenAccessRuntime.Data.GuidConverter.Read(DataHolder& data)
   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.FetchToObjectArray(ResultSet rs, MappingInfo mi)
   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.fetch(FetchResult fetchResult, StateContainer stateContainer)
   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)
Processing 0:  System.InvalidCastException: Specified cast is not valid.
   at System.Data.SqlClient.SqlBuffer.get_SqlGuid()
   at System.Data.SqlClient.SqlDataReader.GetGuid(Int32 i)
   at OpenAccessRuntime.Data.GuidConverter.Read(DataHolder& data)
   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.FetchToObjectArray(ResultSet rs, MappingInfo mi)
   at OpenAccessRuntime.Relational.fetch.FopSqlQuery.fetch(FetchResult fetchResult, StateContainer stateContainer)
   at OpenAccessRuntime.Relational.fetch.FetchSpec.createRow(FetchResult fetchResult, StateContainer stateContainer)

*********************************Class File Function generated by ORM*********************************************


      Public Shared Function PrGetVcancyDetaillForSelectedJob(ByVal scope As IObjectScope, ByVal vacancyID As String, ByVal contactID As Guid, ByVal pageMode As Short) As IQueryResult
            Dim query As IQuery = scope.GetSqlQuery("PrGetVcancyDetaillForSelectedJob ?,?,?", Nothing, "VARCHAR VacancyID,GUID ContactID,SMALLINT PageMode")
            Dim res As IQueryResult = query.Execute(New Object() {vacancyID, contactID, pageMode})
            Dim count As Integer = res.Count 'executes the query
            Return res
      End Function

****************************Stored Procedure Database Script**************************************************


/****** Object:  StoredProcedure [dbo].[PrGetVcancyDetaillForSelectedJob]    Script Date: 05/05/2011 17:44:19 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PrGetVcancyDetaillForSelectedJob]
(
    @VacancyID as nvarchar(max),
    @ContactID as uniqueidentifier,
    @PageMode as tinyint
)    
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    IF(@PageMode=1) -- Add Mode
        begin
            SELECT  0,
                    pdVacancies.VacancyID,
                    pdVacancies.VacancyRef,
                    GETDATE() as VacancyApplicationDate,
                    pdVacancies.VacancyJobTitle,
                    pdVacancies.VacancyDescription,
                    (select COUNT(pdVacancyInterviews.VacancyInterviewID) from pdVacancyInterviews
                        where pdVacancyInterviews.VacancyID=pdVacancies.VacancyID
                        ) as NoOfInterViews
            FROM pdVacancies
            where pdVacancies.VacancyID
            in( Select * from [dbo].[Fn_GetUniqueidentifier_FromString] (@VacancyID))
            --in('63C94C32-238E-480E-9218-00C0505FDC56','361A6F0B-4BF8-45F5-8556-0172DFED41C8','6157B2A0-508B-40B6-8640-022F2DC97662')
            order by pdVacancies.VacancyRef
            
        end
    ELSE IF (@PageMode=2) -- Edit Mode
        begin
            SELECT  pdVacancyApplications.VacancyApplicationID,
                    pdVacancies.VacancyID,
                    pdVacancies.VacancyRef,
                    pdVacancyApplications.VacancyApplicationDate,
                    pdVacancies.VacancyJobTitle,
                    pdVacancies.VacancyDescription,
                    0 as NoOfInterViews
            FROM    pdVacancyApplications Inner join
                    pdVacancies ON pdVacancies.VacancyID = pdVacancyApplications.VacancyID                    
            where pdVacancyApplications.ContactID = @ContactID
            order by pdVacancyApplications.VacancyApplicationDate desc
        end
    
    
 
END


********************************Reverse Mapping.Config**************************************

<procedure name="'PrGetVcancyDetaillForSelectedJob'" method="PrGetVcancyDetaillForSelectedJob">
                <parameter name="@VacancyID" mode="IN" adoType="-1" sqlType="nvarchar(max)" length="0" scale="0" isNull="True" />
                <parameter name="@ContactID" mode="IN" adoType="-11" sqlType="uniqueidentifier" length="0" scale="0" isNull="False" />
                <parameter name="@PageMode" mode="IN" adoType="-6" sqlType="tinyint" length="0" scale="0" isNull="True" />
</procedure>

Thanks and Regards,
Dhaval
0
Ady
Telerik team
answered on 11 May 2011, 04:13 PM
Hi dhaval,

 I was not able to reproduce the error you mention. The error is related to the actual columns returned by the stored procedure. Can you provide details about the column types that are returned by the stored procedure when the exception occurs. I guess that would depend on the value of  the 'PageMode' parameter. I am interested in the actual sql type of each column returned by the 'SELECT' query in the procedure.

Alternatively you can try installing the latest internal build that we released yesterday and verify whether you still get the exception.

Awaiting your reply.

Kind regards,
Ady
the Telerik team
Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
0
John
Top achievements
Rank 2
answered on 22 May 2011, 01:17 PM
HI

I beleive i am experiencing the same problem with a MySQL database.  I have inherited a database abd one of the columns is defined as varchar(32) and for soem strange reason it is treating it as a guid which is strange.  The oher columns which are not size 32 do have the problem.

private System.Nullable<System.Guid> _paymentBankAccountName;
public virtual System.Nullable<System.Guid> PaymentBankAccountName 
    get
    {
        return this._paymentBankAccountName;
    }
    set
    {
        this._paymentBankAccountName = value;
    }
}

the table defintin is as follows

CREATE TABLE sap2k_dat.customers(
  CustomerID INT(10) NOT NULL DEFAULT 0,
  CardRecordID INT(10) DEFAULT NULL,
  CardIdentification VARCHAR(16) DEFAULT NULL,
  Name VARCHAR(127) DEFAULT NULL,
  LastName VARCHAR(127) DEFAULT NULL,
  FirstName VARCHAR(127) DEFAULT NULL,
  IsInactive VARCHAR(10) DEFAULT NULL,
  Notes VARCHAR(255) DEFAULT NULL,
  CustomField1 VARCHAR(30) DEFAULT NULL,
  CustomField2 VARCHAR(30) DEFAULT NULL,
  CustomField3 VARCHAR(30) DEFAULT NULL,
  TermsID INT(10) DEFAULT NULL,
  ABN VARCHAR(14) DEFAULT NULL,
  PriceLevelID CHAR(3) DEFAULT NULL,
  TaxIDNumber VARCHAR(19) DEFAULT NULL,
  TaxCodeID INT(10) DEFAULT NULL,
  FreightTaxCodeID INT(10) DEFAULT NULL,
  CreditLimit DOUBLE(15, 5) DEFAULT NULL,
  MethodOfPaymentID INT(10) DEFAULT NULL,
  PaymentCardNumber VARCHAR(25) DEFAULT NULL,
  PaymentNameOnCard VARCHAR(50) DEFAULT NULL,
  PaymentExpirationDate VARCHAR(10) DEFAULT NULL,
  PaymentBSB VARCHAR(7) DEFAULT NULL,
  PaymentBankAccountNumber VARCHAR(9) DEFAULT NULL,
  PaymentBankAccountName VARCHAR(32) DEFAULT NULL,
  PaymentNotes VARCHAR(255) DEFAULT NULL,
  SalespersonID INT(10) DEFAULT NULL,
  ShippingMethodID INT(10) DEFAULT NULL,
  Street1 VARCHAR(50) DEFAULT NULL,
  City1 VARCHAR(50) DEFAULT NULL,
  State1 VARCHAR(4) DEFAULT NULL,
  Postcode1 VARCHAR(10) DEFAULT NULL,
  Street2 VARCHAR(50) DEFAULT NULL,
  City2 VARCHAR(50) DEFAULT NULL,
  State2 VARCHAR(4) DEFAULT NULL,
  Postcode2 VARCHAR(10) DEFAULT NULL,
  Phone1 VARCHAR(21) DEFAULT NULL,
  Phone2 VARCHAR(21) DEFAULT NULL,
  Phone3 VARCHAR(21) DEFAULT NULL,
  SMS_mobile VARCHAR(20) DEFAULT NULL,
  Fax VARCHAR(21) DEFAULT NULL,
  Email VARCHAR(127) DEFAULT NULL,
  ContactName VARCHAR(25) DEFAULT NULL,
  timestamper TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
  ID INT(11) NOT NULL AUTO_INCREMENT,
  `password` VARCHAR(20) DEFAULT 'password',
  security_role INT(11) DEFAULT 5,
  remote_disc_perc FLOAT DEFAULT 3 COMMENT 'Remote Percentage Discount',
  `directory` VARCHAR(20) DEFAULT NULL,
  DailyFreightFL INT(11) DEFAULT NULL,
  Courier_id INT(11) DEFAULT NULL,
  Bin_No VARCHAR(6) DEFAULT NULL COMMENT 'Carosel Bin Number',
  connote_ref INT(11) DEFAULT NULL,
  PRIMARY KEY (ID),
  INDEX CardRecordID (CardRecordID),
  UNIQUE INDEX CustomerID (CustomerID),
  INDEX customers_lastname (LastName),
  INDEX Postcode1 (Postcode1),
  INDEX SalespersonID (SalespersonID),
  INDEX ShippingMethodID (ShippingMethodID),
  INDEX TaxCodeID (TaxCodeID)
)
ENGINE = INNODB
AUTO_INCREMENT = 2008
AVG_ROW_LENGTH = 814
CHARACTER SET latin1
COLLATE latin1_swedish_ci;

Hope that helps isolating the issue.

Thanks
0
Ady
Telerik team
answered on 25 May 2011, 04:15 PM
Hi John,
 
 We will fix this problem of default mapping a VARCHAR(32) to a System.Guid type. You can nevertheless change the CLR type of the field in the designer. Select the property in the designer, press F4 and select 'System.String' for the 'Type' property. Saving the .rlinq file will generate the code again.

When and what kind of exception do you get? Are you executing a stored procedure that returns a VARCHAR(32) column? Can you provide more details about the exception and also the call stack?

Looking forward to resolving your issue.

Best wishes,
Ady
the Telerik team
Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
0
John
Top achievements
Rank 2
answered on 25 May 2011, 09:58 PM
Hi Ady

Unfortinately i have moved on from there since the post. The exception io recall was that it could not convert the string to a guid much tha same as in the original pist of this thread.  form some reason the ORM was treating that varchar(32) column as a guid not a string.  When i changed the column to varchar(35) the code generate corectly and treated it as a string not a guid.  The error only appeared at runtime.

Hope that helps.

John

0
Ady
Telerik team
answered on 31 May 2011, 02:00 PM
Hi John,
 
 The original error in this post occurs during stored procedure excecution, where the procedure returns a GUID value. In case you have time later on it would be nice if you could send us a sample project where we can reproduce the exception.
I will continue to investigate the matter further.

Kind regards,
Ady
the Telerik team
Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Tags
Data Access Free Edition
Asked by
dhaval
Top achievements
Rank 1
Answers by
Ady
Telerik team
dhaval
Top achievements
Rank 1
John
Top achievements
Rank 2
Share this question
or