none
BUG? Linq dont work with PK NewSequentialId() RRS feed

  • Question

  • In my test project, LINQ have any problems:

    In SQL Server 2005 the table USER with UserID uniqueidentifier and default value NEWSEQUENTIALID()

    In my DBML the UserID Property "Auto Generated Value = True" and "Auto-Sync = OnInsert" in USER Class

    See code:

    User us = new User();
         
          us.Nome = Guid.NewGuid().ToString().Substring(1, 5);

          using (SyncDataContext db = new SyncDataContext())
          {
            db.Users.InsertOnSubmit(us);
            db.SubmitChanges();
          }

    In the line "db.SubmitChanges();" have the exception:

    The target table 'dbo.Usuarios' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.

    Please, help!

    (Sorry my english)

    Juliano Oliveira




    All Exception Code:

    System.Data.SqlClient.SqlException was unhandled
      Message="The target table 'dbo.Usuarios' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause."
      Source=".Net SqlClient Data Provider"
      ErrorCode=-2146232060
      Class=16
      LineNumber=2
      Number=334
      Procedure=""
      Server="juloliveira\\sqlexpress"
      State=1
      StackTrace:
           em System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
           em System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
           em System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
           em System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, TdsParserStateObject stateObj)
           em System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
           em System.Data.SqlClient.SqlDataReader.get_MetaData()
           em System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
           em System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
           em System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
           em System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
           em System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
           em System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
           em System.Data.Common.DbCommand.ExecuteReader()
           em System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
           em System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
           em System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
           em System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicInsert(TrackedObject item)
           em System.Data.Linq.ChangeDirector.StandardChangeDirector.Insert(TrackedObject item)
           em System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
           em System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
           em System.Data.Linq.DataContext.SubmitChanges()
           em Linq.Form1.button1_Click(Object sender, EventArgs e) na C:\Users\Juliano\Documents\Visual Studio 2008\Projects\Linq\Linq\Form1.cs:linha 39
           em System.Windows.Forms.Control.OnClick(EventArgs e)
           em System.Windows.Forms.Button.OnClick(EventArgs e)
           em System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
           em System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
           em System.Windows.Forms.Control.WndProc(Message& m)
           em System.Windows.Forms.ButtonBase.WndProc(Message& m)
           em System.Windows.Forms.Button.WndProc(Message& m)
           em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
           em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
           em System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
           em System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
           em System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
           em System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
           em System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
           em System.Windows.Forms.Application.Run(Form mainForm)
           em Linq.Program.Main() na C:\Users\Juliano\Documents\Visual Studio 2008\Projects\Linq\Linq\Program.cs:linha 18
           em System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
           em System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           em Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           em System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           em System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           em System.Threading.ThreadHelper.ThreadStart()
      InnerException:

    Saturday, September 13, 2008 4:53 PM

Answers

  • Can you turn on logging with db.Log = Console.Out (or something similar for non-console apps) to see what SQL statements are operating.

    Do you have any triggers in your database?

    [)amien
    Saturday, September 13, 2008 8:48 PM
    Moderator

All replies

  • Can you turn on logging with db.Log = Console.Out (or something similar for non-console apps) to see what SQL statements are operating.

    Do you have any triggers in your database?

    [)amien
    Saturday, September 13, 2008 8:48 PM
    Moderator
  • Thanks to tip, Log property é very goody.

    Well, In debug see this code:

    DECLARE @output TABLE([idUsuario] UniqueIdentifier)
    INSERT INTO [dbo].[Usuarios]([Nome], [LastEditDate], [CreationDate])
    OUTPUT INSERTED.[idUsuario]
    VALUES (@p0, @p1, @p2)
    SELECT [idUsuario] FROM @output
    -- @p0: Input VarChar (Size = 5; Prec = 0; Scale = 0) [2e248]
    -- @p1: Input DateTime (Size = 0; Prec = 0; Scale = 0) [Null]
    -- @p2: Input DateTime (Size = 0; Prec = 0; Scale = 0) [Null]
    -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30428.1

    A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.Linq.dll

    And the same error.

    In my my database i dont have triggers. I need one trigger ? You can show me a example in this case ?

    Thanks Damien
    Saturday, September 13, 2008 9:33 PM
  • Sorry Damien,

    A have TREE triggers created with SYNC FRAMEWORK

    I delete the triggers

    Now is OK!

    Thanks!!!

    But, if need trigger to UPDATE fields LASTUPDATED and CREATEDAT (datetime) i need in triggers send OUTPUT ???


    Thanks again
    Saturday, September 13, 2008 9:43 PM