Click here to Skip to main content
14,699,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Pls some one tell that how to send or upload excel sheet data to sql server , i have created a code and it running perfectly on local system, but when i used this code on server side it throwing an error that excel sheet path is also opened by another user with oledb connection.

this is my code Pls some one tell that what should i do with code to work on server side.

protected void cmdImport_Click(object sender, EventArgs e)
string sSourceConstr = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\AgentList.xls; Extended Properties=""Excel 8.0;HDR=YES;""";
string sDestConstr = ConfigurationManager.ConnectionStrings["TestConnection"].ConnectionString;
OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
using (sSourceConnection)
string sql = string.Format("Select [MSISDN],[Name],[Company],[Status] FROM [{0}]", "Sheet1$");
OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
using (OleDbDataReader dr = command.ExecuteReader())
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sDestConstr))
bulkCopy.DestinationTableName = "tblAgent";
//You can mannualy set the column mapping by the following way.
//bulkCopy.ColumnMappings.Add("MSISDN", "MSISDN");

i have done columnmapping also with my code.Pls some one tell......
Updated 9-Mar-12 22:22pm

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