public void SaveError(Error e)
{
string connectionString = Properties.Settings.Default.PlatinumDBConnectionString;
string cmdString =
"INSERT INTO dbo.Errors(eName,eInstance,eMessage,eModule,eProcedure,eUserId,eUserMessage,ecName,ecCode,ecDescription,ecMessage) VALUES (@val1, @va2, @val3,@val4,@val5,@val6,@val7,@val8,@val9,@val10,@val11)";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand(cmdString, conn))
{
cmd.Parameters.AddWithValue("@val1", e.Name);
cmd.Parameters.AddWithValue("@val2", e.Instance);
cmd.Parameters.AddWithValue("@val3", e.Message);
cmd.Parameters.AddWithValue("@val4", e.Module);
cmd.Parameters.AddWithValue("@val5", e.Procedure);
cmd.Parameters.AddWithValue("@val6", e.UserId);
cmd.Parameters.AddWithValue("@val7", e.UserMessage);
cmd.Parameters.AddWithValue("@val8", e.ErrorCode.Name);
cmd.Parameters.AddWithValue("@val9", e.ErrorCode.Code);
cmd.Parameters.AddWithValue("@val10", e.ErrorCode.Description);
cmd.Parameters.AddWithValue("@val11", e.ErrorCode.Message);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
#endregion
}
I added the transaction command but still no row created
public void SaveError(Error e)
{
string connectionString = Properties.Settings.Default.PlatinumDBConnectionString;
string cmdString =
"INSERT INTO dbo.Errors(eName,eInstance,eMessage,eModule,eProcedure,eUserId,eUserMessage,ecName,ecCode,ecDescription,ecMessage) VALUES (@val1, @va2, @val3,@val4,@val5,@val6,@val7,@val8,@val9,@val10,@val11)";
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
SqlTransaction trans = conn.BeginTransaction();
using (SqlCommand cmd = new SqlCommand(cmdString, conn))
{
cmd.Transaction = trans;
cmd.Parameters.AddWithValue("@val1", e.Name);
cmd.Parameters.AddWithValue("@val2", e.Instance);
cmd.Parameters.AddWithValue("@val3", e.Message);
cmd.Parameters.AddWithValue("@val4", e.Module);
cmd.Parameters.AddWithValue("@val5", e.Procedure);
cmd.Parameters.AddWithValue("@val6", e.UserId);
cmd.Parameters.AddWithValue("@val7", e.UserMessage);
cmd.Parameters.AddWithValue("@val8", e.ErrorCode.Name);
cmd.Parameters.AddWithValue("@val9", e.ErrorCode.Code);
cmd.Parameters.AddWithValue("@val10", e.ErrorCode.Description);
cmd.Parameters.AddWithValue("@val11", e.ErrorCode.Message);
cmd.ExecuteNonQuery();
trans.Commit();
}
conn.Close();
}
}
Here is the server dump from the table
USE [PlatinumDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Errors](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[eName] [nchar](50) NULL,
[eInstance] [nchar](50) NULL,
[eMessage] [nvarchar](max) NULL,
[eModule] [nvarchar](50) NULL,
[eProcedure] [nvarchar](50) NULL,
[eUserId] [nvarchar](50) NULL,
[eUserMessage] [nvarchar](max) NULL,
[ecName] [nchar](50) NULL,
[ecCode] [nchar](50) NULL,
[ecDescription] [nvarchar](max) NULL,
[ecMessage] [nvarchar](max) NULL,
CONSTRAINT [PK_Errors] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO