New Posts New Posts RSS Feed: Error when saving using Insert, Update, Delete Stored Procedures and  UseSqlIdentityProc
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Error when saving using Insert, Update, Delete Stored Procedures and UseSqlIdentityProc

 Post Reply Post Reply
Author
greenman View Drop Down
Newbie
Newbie
Avatar

Joined: 05-Sep-2007
Location: Italy
Posts: 3
Post Options Post Options   Quote greenman Quote  Post ReplyReply Direct Link To This Post Topic: Error when saving using Insert, Update, Delete Stored Procedures and UseSqlIdentityProc
    Posted: 05-Sep-2007 at 1:56am

I've followed your Instructional Unit about using Stored Procedures to do all the persistence.

 
I've implemented a StoredProcedureDataProvider that do the same things of yours (I've copied it and modified some minor things like parameter names etc...).
My database (SQL 2005) has 2 schemas, all 2 schemas are mapped using Object Mapper with 2 keys that have full permission for mapping porpouses.
At runtime inside IdeaBlade.ibconfig the 2 keys have been modified with different connection strings: "default" with full rights (sa) that is used in Entities mapped to "dbo" schema, "cmp" with a user that is owner of "cmp" schema  (used in Entities mapped to that schema)and can only execute on "dbo" schema, this for security porpouses.
All Insert/Update/Delete SPs belong to "cmp" schema so my classes can to that (in fact, Update and Delete DO WORK!)
With Management Studio I've prepared and runned (runned, using "cmp" account to be sure) the stored procedure "usp_IdeaBlade_SqlIdentityGenerator" and all works great, assuring me that user "cmp" has the right to execute even the "usp_IdeaBlade_SqlIdentityGenerator" SP (as well as all dbo's SP).
When, in my code, I try to invoke "SaveChanges" of the PM, it throw an exception:

((IdeaBlade.Persistence.PersistenceManagerSaveException)(ex))

Save failed - Length cannot be less than zero.
Parameter Name: length

"IdeaBlade.Persistence"

"  in IdeaBlade.Persistence.PersistenceManager.DoSaveDataSet(IEnumerable pDataRows, SaveOptions pSaveOptions)
   in IdeaBlade.Persistence.PersistenceManager.SaveChanges(IEnumerable pDataRows, SaveOptions pSaveOptions)
   in IdeaBlade.Persistence.PersistenceManager.SaveChanges()
   in ConsoleApplication1.Program2.Save(PersistenceManager pm) in F:\Visual Studio 2005\Projects\DevForceTest\ConsoleApplication1\Program2.cs:riga 35"


((System.ArgumentOutOfRangeException)(ex.InnerException))

Length cannot be less than zero.
Parameter Name: length

"mscorlib"

"  in System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
   in System.String.Substring(Int32 startIndex, Int32 length)
   in IdeaBlade.Persistence.Server.TransactionManagerHelper.SaveTableWithSqlProcPart2(EntityTable pTable)
   in IdeaBlade.Persistence.Server.TransactionManagerHelper.SaveTable(EntityTable pTable, Boolean pDeleting, PostSaveHandler pPostSaveHandler, Boolean pExcludeFromRefetch)
   in IdeaBlade.Persistence.Server.TransactionManagerHelper.SaveTableWithSqlProc(RdbKey pRdbKey, EntityTable pTable, Boolean pExcludeFromRefetch)
   in IdeaBlade.Persistence.Server.TransactionManagerHelper.Save(DataSet pDataSet, SaveOptions pSaveOptions)"

It seems to be something that doesn't belong to my implementation but maybe a bug when using a custom IAdapterProvider in conjunction with usp_IdeaBlade_SqlIdentityGenerator.

 
I've some limitation about users that can access datasource and StoredProcedures for CRUD opreations are by design.

Thank you for all support.



Edited by greenman - 05-Sep-2007 at 2:00am
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 05-Sep-2007 at 12:30pm
Writing your own custom IAdapterProvider is definitely an advanced topic, and if this is your first attempt at writing one, I'm not surprised to find  that you were not immediately successful.
 
I suspect that your problem is that your IAdapterProvider is not emitting the right SQL.  The first place to look should be the DebugLog.XML file in your client bin/Debug directory.  If you can find the SQL that is being generated, you can look to see if it looks correct.  I know that you say that your Stored Procedures work just fine, but just because they work standalone does not mean that they will work in the context of an IAdapterProvider.
 
If you can't find any SQL in the DebugLog.XML, things are a bit more difficult because it means your application blew up before it could even generate the SQL.  If this happens, I would go back to the Tutorial and study it some more, perhaps trying to make some very small changes.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down