This is my code so far:
public class ServerUtility
{
public static int LogError(string source, string detail)
{
int iresult = -99;
try
{
BaseRepository repo = new BaseRepository();
using (SqlConnection con = new SqlConnection(repo.connectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand($"INSERT INTO [dbo].[LogError]([source],[detail],[date])VALUES('{source.Replace("'", "''")}','{detail.Replace("'", "''")}',GETDATE());SELECT @@IDENTITY", con))
{
string getValue = cmd.ExecuteScalar().ToString();
iresult = Convert.ToInt32(getValue);
} // command disposed here
} //connection closed and disposed here
}
catch (Exception ex) { throw ex; }
return iresult;
}
}
My question is on GetInstance method :
BaseRepository repo = new BaseRepository();
using (SqlConnection con = new SqlConnection(repo.connectionString))
I am always set it as new object, on my static function, just for get constant value from AppSetting.
What actually happened if I implement this code to my project? How about the performance?
Is it cause performance issue?
Thanks