# 長榮S6 DB 錯誤 ## 建立錯誤 ```sql= [16:45:10] SQL Error: declare @aa_sid int declare @old_at_sid int Select Top 1 @aa_sid=aa_sid, @old_at_sid=at_sid From Agt_Account Where ao_sid = @ao_sid And aa_id = @username; if(@aa_sid is null) begin Insert Into Agt_Account (ao_sid, at_sid, aa_name, aa_id, aa_pw, aa_post, aa_email, is_default, aa_begin, aa_end, is_enable) Values (@ao_sid, @at_sid, @displayname, @username, @aa_pw, @title, @aa_email, 1, getdate(), DATEADD(year, 50, getdate()), 1) set @aa_sid = Scope_Identity() select @old_at_sid=at_sid from Agt_Account where aa_sid=@aa_sid Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end if(@old_at_sid<>@at_sid) begin Update Agt_Account Set at_sid = @at_sid Where aa_sid = @aa_sid And ao_sid = @ao_sid; Delete Agt_GroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_FaqGroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_AccAnswer Where ao_sid = @ao_sid and aa_sid = @aa_sid; Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end select aa_id as account,aa_name as name,aa_email as email,ao_sid,'basic' as pm_id from Agt_Account where aa_sid=@aa_sid para:{"ao_sid":281,"username":"lianlin","at_sid":807,"displayname":"LianLin","aa_pw":"lujSdhC6uyIZwk7CsnGI","title":"RD","aa_email":null} [16:45:10] System.Data.SqlClient.SqlException (0x80131904): 無法插入 NULL 值到資料行 'aa_email',資料表 'KB52.dbo.Agt_Account'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_GroupAcc'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_AccAnswer'; 資料行不得有 Null。INSERT 失敗。 陳述式已經結束。 陳述式已經結束。 陳述式已經結束。 於 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 於 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 於 System.Data.SqlClient.SqlDataReader.get_MetaData() 於 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) 於 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader() 於 ZapLib.SQL.Query(String sql, Object param) 於 ZapLib.SQL.QuickQuery[T](String sql, Object param, Boolean isfetchall) ClientConnectionId:3577a554-1810-42f8-96b0-88b6d2e2aec6 Error Number:515,State:2,Class:16 ``` ## 錯誤訊息 ```sql= [16:45:21] SQL Error: declare @aa_sid int declare @old_at_sid int Select Top 1 @aa_sid=aa_sid, @old_at_sid=at_sid From Agt_Account Where ao_sid = @ao_sid And aa_id = @username; if(@aa_sid is null) begin Insert Into Agt_Account (ao_sid, at_sid, aa_name, aa_id, aa_pw, aa_post, aa_email, is_default, aa_begin, aa_end, is_enable) Values (@ao_sid, @at_sid, @displayname, @username, @aa_pw, @title, @aa_email, 1, getdate(), DATEADD(year, 50, getdate()), 1) set @aa_sid = Scope_Identity() select @old_at_sid=at_sid from Agt_Account where aa_sid=@aa_sid Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end if(@old_at_sid<>@at_sid) begin Update Agt_Account Set at_sid = @at_sid Where aa_sid = @aa_sid And ao_sid = @ao_sid; Delete Agt_GroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_FaqGroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_AccAnswer Where ao_sid = @ao_sid and aa_sid = @aa_sid; Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end select aa_id as account,aa_name as name,aa_email as email,ao_sid,'basic' as pm_id from Agt_Account where aa_sid=@aa_sid para:{"ao_sid":281,"username":"lianlin","at_sid":807,"displayname":"LianLin","aa_pw":"lujSdhC6uyIZwk7CsnGI","title":"RD","aa_email":null} ``` ## 錯誤訊息 ```sql= [16:45:21] System.Data.SqlClient.SqlException (0x80131904): 無法插入 NULL 值到資料行 'aa_email',資料表 'KB52.dbo.Agt_Account'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_GroupAcc'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_AccAnswer'; 資料行不得有 Null。INSERT 失敗。 陳述式已經結束。 陳述式已經結束。 陳述式已經結束。 於 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 於 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 於 System.Data.SqlClient.SqlDataReader.get_MetaData() 於 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) 於 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader() 於 ZapLib.SQL.Query(String sql, Object param) 於 ZapLib.SQL.QuickQuery[T](String sql, Object param, Boolean isfetchall) ClientConnectionId:3577a554-1810-42f8-96b0-88b6d2e2aec6 Error Number:515,State:2,Class:16 ``` ## 第一階段 ```SQL= SQL Error: declare @aa_sid int declare @old_at_sid int Select Top 1 @aa_sid=aa_sid, @old_at_sid=at_sid From Agt_Account Where ao_sid = @ao_sid And aa_id = @username; if(@aa_sid is null) begin Insert Into Agt_Account (ao_sid, at_sid, aa_name, aa_id, aa_pw, aa_post, aa_email, is_default, aa_begin, aa_end, is_enable) Values (@ao_sid, @at_sid, @displayname, @username, @aa_pw, @title, @aa_email, 1, getdate(), DATEADD(year, 50, getdate()), 1) set @aa_sid = Scope_Identity() select @old_at_sid=at_sid from Agt_Account where aa_sid=@aa_sid Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end if(@old_at_sid<>@at_sid) begin Update Agt_Account Set at_sid = @at_sid Where aa_sid = @aa_sid And ao_sid = @ao_sid; Delete Agt_GroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_FaqGroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_AccAnswer Where ao_sid = @ao_sid and aa_sid = @aa_sid; Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end select aa_id as account,aa_name as name,aa_email as email,ao_sid,'basic' as pm_id from Agt_Account where aa_sid=@aa_sid para:{"ao_sid":281,"username":"lianlin","at_sid":807,"displayname":"LianLin","aa_pw":"lujSdhC6uyIZwk7CsnGI","title":"RD","aa_email":null} ``` ## 第二階段 ```SQL= [16:45:10] System.Data.SqlClient.SqlException (0x80131904): 無法插入 NULL 值到資料行 'aa_email',資料表 'KB52.dbo.Agt_Account'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_GroupAcc'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_AccAnswer'; 資料行不得有 Null。INSERT 失敗。 陳述式已經結束。 陳述式已經結束。 陳述式已經結束。 於 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 於 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 於 System.Data.SqlClient.SqlDataReader.get_MetaData() 於 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) 於 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader() 於 ZapLib.SQL.Query(String sql, Object param) 於 ZapLib.SQL.QuickQuery[T](String sql, Object param, Boolean isfetchall) ClientConnectionId:3577a554-1810-42f8-96b0-88b6d2e2aec6 Error Number:515,State:2,Class:16 ``` ## 第三階段 ```SQL= [16:45:21] SQL Error: declare @aa_sid int declare @old_at_sid int Select Top 1 @aa_sid=aa_sid, @old_at_sid=at_sid From Agt_Account Where ao_sid = @ao_sid And aa_id = @username; if(@aa_sid is null) begin Insert Into Agt_Account (ao_sid, at_sid, aa_name, aa_id, aa_pw, aa_post, aa_email, is_default, aa_begin, aa_end, is_enable) Values (@ao_sid, @at_sid, @displayname, @username, @aa_pw, @title, @aa_email, 1, getdate(), DATEADD(year, 50, getdate()), 1) set @aa_sid = Scope_Identity() select @old_at_sid=at_sid from Agt_Account where aa_sid=@aa_sid Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end if(@old_at_sid<>@at_sid) begin Update Agt_Account Set at_sid = @at_sid Where aa_sid = @aa_sid And ao_sid = @ao_sid; Delete Agt_GroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_FaqGroupAcc Where ao_sid = @ao_sid and aa_sid = @aa_sid; Delete Agt_AccAnswer Where ao_sid = @ao_sid and aa_sid = @aa_sid; Insert Into Agt_GroupAcc (ao_sid, ag_sid, aa_sid) Select Top 1 ao_sid, ag_sid, @aa_sid From Agt_Group Where ao_sid = @ao_sid And ag_name = '一般使用者'; Insert Into Agt_FaqGroupAcc (ao_sid, afg_sid, aa_sid) Select Top 1 ao_sid, afg_sid, @aa_sid From Agt_FaqGroup Where ao_sid = @ao_sid And afg_name = 'Public'; Insert Into Agt_AccAnswer (ao_sid, aa_sid, fan_sid, is_edit) Select ao_sid, @aa_sid, fan_sid, 0 From Faq_AnswerName Where ao_sid = @ao_sid; end select aa_id as account,aa_name as name,aa_email as email,ao_sid,'basic' as pm_id from Agt_Account where aa_sid=@aa_sid para:{"ao_sid":281,"username":"lianlin","at_sid":807,"displayname":"LianLin","aa_pw":"lujSdhC6uyIZwk7CsnGI","title":"RD","aa_email":null} ``` ## 第四階段 ```SQL= [16:45:21] System.Data.SqlClient.SqlException (0x80131904): 無法插入 NULL 值到資料行 'aa_email',資料表 'KB52.dbo.Agt_Account'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_GroupAcc'; 資料行不得有 Null。INSERT 失敗。 無法插入 NULL 值到資料行 'aa_sid',資料表 'KB52.dbo.Agt_AccAnswer'; 資料行不得有 Null。INSERT 失敗。 陳述式已經結束。 陳述式已經結束。 陳述式已經結束。 於 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) 於 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) 於 System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) 於 System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() 於 System.Data.SqlClient.SqlDataReader.get_MetaData() 於 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) 於 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) 於 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 於 System.Data.SqlClient.SqlCommand.ExecuteReader() 於 ZapLib.SQL.Query(String sql, Object param) 於 ZapLib.SQL.QuickQuery[T](String sql, Object param, Boolean isfetchall) ClientConnectionId:3577a554-1810-42f8-96b0-88b6d2e2aec6 Error Number:515,State:2,Class:16 ```