0
私はVb.netとLinq2sqlを初めて使用しています。ここで質問を投稿する前に解決策をGoogleで検索しましたが、修正できませんでした。 Vb.netとLinq2sqlを使用して、データベースに行を追加すると、SubmitChanges()関数は '@errno' SQl Exceptionの近くに誤った構文を返します。Sql例外 '@errno'の近くにある構文が正しくありません
私のコード:
Public Sub NewProfile(connectionString As String, code As String, name As String)
Dim db As RosterDataContext = CreateRosterDataContext(connectionString, True)
' Business validations
Try
Dim q =
From p In db.Profiles
Select p
Where p.ProfileCode = code Or p.ProfileName = name
Dim old As Profile = q.SingleOrDefault()
If Not IsNothing(old) AndAlso Not IsNothing(old.ProfileCode) Then
Throw New DuplicateKeyException("Duplicated Profile Code or Profile Name")
End If
Catch ex As DuplicateKeyException
Log.LogInfo(ex)
Return
End Try
' Insert into the DB
Dim profile As Profile = New Profile()
profile.ProfileName = name
profile.ProfileCode = code
profile.CreatedBy = If(IsNothing(UserIdentity.User), String.Empty, UserIdentity.User.UserID)
profile.IsSysAdmin = "N"
profile.IsSystenDefined = "N"
profile.LastUpdatedBy = profile.CreatedBy
profile.UtcDateCreated = DateTime.UtcNow
profile.UtcDateLastUpdated = profile.UtcDateCreated
db.Profiles.InsertOnSubmit(profile)
Try
db.SubmitChanges()
Catch ex As ChangeConflictException
db.ChangeConflicts.ResolveAll(RefreshMode.KeepChanges)
db.SubmitChanges()
End Try
End Sub
プロフィールがデータベースにPROFILEテーブルにマップされたクラスが存在します。.. このテーブルに関連するトリガであり:
USE [Roster]
GO
/****** Object: Trigger [dbo].[ti_profile] Script Date: 11/14/2017
4:17:00 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[ti_profile] on [dbo].[PROFILE] AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @ls_profile_code varchar(6)
declare @errno int
declare @errmsg varchar(255)
--set @ls_profile_code = select inserted.profile_code from inserted
-- insert what ever was added to the object table and not yet been inserted or updated in the profile_access
insert into Profile_access (profile_code , object_code)
select (select inserted.profile_code from inserted) ,
object_code
from Objects
where object_code not in
(
select object_code
from Profile_access
where profile_code = @ls_profile_code
)
return
error:
raiserror @errno @errmsg
rollback transaction
END
どのように上の任意のアイデアこれを修正してください..
最初のタグ... MySQLは同じではありませんSQLサーバー。 –
プロファイルとはどのようにしてデータベースにリンクしていますか?あなたは@errnoパラメータでトリガまたは関数を持っていますか? –
@RaymondNijlandありがとう、それは間違いだった – Furqan