Click here to Skip to main content
15,909,325 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am getting this error from server when inserting record to database.

What I have tried:

I dont know from where this error come
Posted
Updated 15-Jan-18 10:17am
Comments
Dave Kreskowiak 15-Jan-18 1:01am    
So? Do what the message says. What does the Inner Exception property of the Exception you got say?

That's the best answer you're going to get right now. You've given us absolutely NOTHING to go on. There's nothing anyone in the world can do to help you with the complete lack of information you've provided.
ADI@345 15-Jan-18 1:11am    
void recordbind()
{

if (Session["adminhome"] != null)
{

lblSales.Text = Session["adminhome"].ToString();

}

SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
cnn.Open();
SqlCommand comm = new SqlCommand();
string quiry = "BEGIN TRY " +
"BEGIN TRANSACTION " +
"INSERT INTO [dsr_data]([session_name],[currentdate],[client_type],[date_time],[tme],[area],[company_name],[client_name],[mobile],[email],[address_name],[landmark],[curr_presence_appoint],[status_type],[result],[comment])";

if (ddlctype.Text != "Select")
{
quiry += " select '" + lblSales.Text + "', '" + lbldate.Text + "', '" + ddlctype.Text.Trim() + "','" + txtDate.Text.Trim() + "','" + ddltme.Text.Trim() + "','" + txtarea.Text.Trim() + "','" + txtcname.Text.Trim() + "','" + txtclientname.Text.Trim() + "', '" + txtmobile.Text.Trim() + "','" + txtemail.Text.Trim() + "','" + txtaddress.Text.Trim() + "','" + txtlandmark.Text.Trim() + "','" + txtcurr.Text.Trim() + "','" + ddlstatus.Text.Trim() + "','" + ddlresult.Text.Trim() + "','" + txtcomment.Text.Trim() + "'";
}

if (DropDownList1.Text != "Select")


quiry += " COMMIT TRANSACTION " +
"END TRY " +
"BEGIN CATCH " +
"ROLLBACK TRANSACTION " +
" END CATCH";


comm.Connection = cnn;
comm.CommandType = CommandType.Text;
comm.CommandText = quiry;

try
{

comm.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Information Save Successfully.');", true);

}

catch (Exception ex)
{
Response.Write(ex.Message);
}

}

1 solution

The problem is your connection string & /or server configuration.
Your connection string does not include a SQL Username & Password but instead are using Integrated Security or Trusted_Connection in your string with the value set to SSPI.
The error is advising that the SQL Server is unable to authenticate the User that is making the request.
This can be caused by several reasons for example;
a) SQL is running under a local account that cannot query the domain controller to determine if the user making the request has the required permissions
b) The account that is making the request (I would suggest this is a website due to the ScriptManager reference) does not have permission to access the DB, probably because the website is running under a local account on your web server

Review how you are connecting to SQL & create an appropriate connection string - the below links will assist.
SqlConnection.ConnectionString Property (System.Data.SqlClient)[^]
ConnectionStrings.com - Forgot that connection string? Get it here![^]

Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900