RE: [nhibernate-development] could not execute native bulk manipulation with an inner exception of 'The given key was not present in the dictionary' when executing SQL 2008 Stored Procedure

3,724 views
Skip to first unread message

Richard Wilde

unread,
Nov 26, 2012, 8:31:05 AM11/26/12
to nhibernate-...@googlegroups.com

Are you missing:-

 

 query.SetString("RefreshToken ", “what ever your token is”);

 

Rippo

 

 

From: nhibernate-...@googlegroups.com [mailto:nhibernate-...@googlegroups.com] On Behalf Of Paul Chapman
Sent: 25 November 2012 22:29
To: nhibernate-...@googlegroups.com
Subject: [nhibernate-development] could not execute native bulk manipulation with an inner exception of 'The given key was not present in the dictionary' when executing SQL 2008 Stored Procedure

 

I get the following error when executing a stored procedure

 

could not execute native bulk manipulation query:exec EmailAuthorizationsInsert @Id=:Id @Email=:Email @AccessToken=:AccessToken @Expiration=:Expiration @Issued=:Issued @RefreshToken=:RefreshToken[SQL: SQL not available]

 

Inner Exception is

 

The given key was not present in the dictionary

 

hibernate.cfg.xml

 

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Data Source=pc-acer\dev;Initial Catalog=Email;Integrated Security=True</property>
    <property name="show_sql">true</property>
  </session-factory>
</hibernate-configuration>
 
EmailAuthorization.hbm.xml
 
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="GoogleEmailClient" namespace="GoogleEmailClient.BusinessObjects">
  <class name="EmailAuthorization" table="EmailAuthorizations">
    <id name="Id">
      <generator class="guid" />
    </id>
    <property name="Email" />
    <property name="AccessToken" />
    <property name="Expiration" />
    <property name="Issued" />
    <property name="RefreshToken" />
  </class>
</hibernate-mapping>
 
Code to execute Stored Procedure
 
            ISession session = NHibernateHelper.GetCurrentSession();
            IQuery query = session.CreateSQLQuery("exec EmailAuthorizationsInsert @Id=:Id @Email=:Email @AccessToken=:AccessToken @Expiration=:Expiration @Issued=:Issued @RefreshToken=:RefreshToken");
 
            query.SetGuid("Id"Guid.NewGuid());
            query.SetString("Email", user);
            query.SetString("AccessToken", grantedAccess.AccessToken);
            query.SetDateTime("Expiration",Convert.ToDateTime(grantedAccess.AccessTokenExpirationUtc));
            query.SetDateTime("Issued"Convert.ToDateTime(grantedAccess.AccessTokenIssueDateUtc));
 
            query.ExecuteUpdate();

 

Stored Procedure being executed

 

CREATE PROCEDURE [dbo].[EmailAuthorizationsInsert]

            @ID                                        UniqueIdentifier,

            @Email                                   VarChar(MAX),

            @AccessToken           VarChar(MAX),

            @Expiration                DateTime,

            @Issued                                  DateTime,

            @RefreshToken          VarChar(MAX)

AS

BEGIN

            SET NOCOUNT ON;

 

            INSERT INTO EmailAuthorizations

                (Email

                , AccessToken

                , Expiration

                , Issued

                , RefreshToken)

            VALUES     (@Email

                                                , @AccessToken

                                                , @Expiration

                                                , @Issued

                                                , @RefreshToken)

END

 

 

And for completeness the table definition

 

USE [Email]

GO

 

/****** Object:  Table [dbo].[EmailAuthorizations]    Script Date: 11/25/2012 22:28:04 ******/

SET ANSI_NULLS ON

GO

 

SET QUOTED_IDENTIFIER ON

GO

 

SET ANSI_PADDING ON

GO

 

CREATE TABLE [dbo].[EmailAuthorizations](

            [ID] [uniqueidentifier] NOT NULL,

            [Email] [varchar](max) NOT NULL,

            [AccessToken] [varchar](max) NOT NULL,

            [Expiration] [datetime] NOT NULL,

            [Issued] [datetime] NOT NULL,

            [RefreshToken] [varchar](max) NOT NULL

) ON [PRIMARY]

 

GO

 

SET ANSI_PADDING OFF

GO

 

Any ideas 

 

Thanks in advance

Stephen Bohlen

unread,
Nov 26, 2012, 3:34:34 PM11/26/12
to nhibernate-development
I'd like to request that this thread be continued on the NHUSERS forum (http://groups.google.com/group/nhusers/) where its really more appropriate.  This list is actually for the discussion of development *of* NHibernate rather than development *with* NHibernate.

Thanks,

-Steve B.

Steve Bohlen
sbo...@gmail.com
http://blog.unhandled-exceptions.com
http://twitter.com/sbohlen


On Mon, Nov 26, 2012 at 3:25 PM, Paul Chapman <paulsch...@gmail.com> wrote:
I spent an entire evening looking at that and failed to notice, thanks anyway - that has at least got rid of that error - it is now giving me; Incorrect syntax near '@Email'.
Reply all
Reply to author
Forward
0 new messages