2
string filepath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filepath);
string ext = Path.GetExtension(filename);
String strConnection = "Data Source=192.168.51.02;Initial Catalog=****;User   ID=*****;Password=*****;Integrated Security=True";
string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=\"Excel 12.0 Xml;HRD=YES;IMEX=1;\"";

OleDbConnection excelConnection = new OleDbConnection(excelConnectionString);

OleDbCommand cmd = new OleDbCommand("Select [Emp ID],[Emp Name],[Log Date],[Logtime],[Type] from [One Month Report$]", excelConnection);
excelConnection.Open();

//cmd.ExecuteNonQuery();


//DataSet ds = new DataSet();
//SqlDataAdapter da = new SqlDataAdapter("Select [sno],[Name],[Designation] from [Sheet1$]", strConnection);

OleDbDataReader dReader;
dReader = cmd.ExecuteReader();
SqlBulkCopy sqlBulk = new SqlBulkCopy(strConnection);

sqlBulk.DestinationTableName = "K_Master_EmpAttendanceDet";
sqlBulk.WriteToServer(dReader);
excelConnection.Close();

I want import data from excel to database using asp.net .I have tried like this but I am getting this error:

Login failed for user. The user is not associated with a trusted SQL Server connection.

Is it require any Dll file or any thing wrong in my code. Please Help me.

1 Answer 1

2
Just Remove the "integrated security" part from your strConnection . Here your connection will use the windows authentication instead of the sql authentication. 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.