Forum Discussion
3 Replies
- mspatelContributorError is Attached to post .
Can somebody help ? - RavikSuper ContributorHi Manish,
Try this sample it's may help you-
string strFileType = System.IO.Path.GetExtension(filepath.ToLower());
string sSourceConstr = String.Empty;
if (strFileType.Trim() == ".xls")
{
sSourceConstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + filepath + "; Extended Properties=\"Excel 8.0; HDR=Yes; IMEX=2\"";
}
else if (strFileType.Trim() == ".xlsx")
{
sSourceConstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" + filepath + "; Extended Properties=\"Excel 12.0; HDR=Yes; IMEX=2\"";
}
string sDestConstr = ConfigurationManager.ConnectionStrings["Class"].ConnectionString;
OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
using (sSourceConnection)
{
sSourceConnection.Open();
string sql = "select * from [" + dr["SheetName"].ToString() + "]"; //"select * from $",sheet OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
OleDbDataAdapter da = new OleDbDataAdapter();
da = new OleDbDataAdapter(command);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables.Count > 0)
{
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
Users objUser = (Users)Session["UserSession"];
string curUser = objUser.UserId;
DataColumn dcUser = new DataColumn();
dcUser.ColumnName = "CreatedBy";
dcUser.DefaultValue = curUser;
dt.Columns.Add(dcUser);
DataColumn dcCreatedOn = new DataColumn();
dcCreatedOn.ColumnName = "CreatedOn";
dcCreatedOn.DataType = System.Type.GetType("System.DateTime");
dcCreatedOn.DefaultValue = DateTime.Now;
dt.Columns.Add(dcCreatedOn);
int newsNo = dt.Rows.Count;
string table = ("ZipUpload"+"_"+dr["SheetName"].ToString().Replace("$",""));
string conString = ConfigurationManager.ConnectionStrings["Class"].ConnectionString;
CommonBase objCommonBase = new CommonBase();
objCommonBase.DeletTableData(table);
FileUploadBase objFileUpload = new FileUploadBase();
objFileUpload.BulkInsert(dt, table, conString);
lblMessage.Text = "File uploaded successfully! No. of Record: " + newsNo + " ";
lblMessage.ForeColor = System.Drawing.Color.Green; - RavikSuper Contributor
1.
This commonly occurs when your database file is opened exclusively by another application (usually MS Access MS Excel). Close all applications that use this database, all instance of Excel and try again.
2.
This error may occur if the account being used by Internet Information Server (IIS), (usually IUSR), does not have the correct Windows NT permissions for a file-based database or for the folder containing the file.
3.
Check the permissions on the file and the folder. Make sure that you have the ability to create and/or destroy any temporary files. Temporary files are usually created in the same folder as the database, but the file may also be created in other folders such as /Winnt.
4.
If you use a network path to the database (UNC or mapped drive), check the permissions on the share, the file, and the folder.
5.
Check to make sure that the file and the data source name (DSN) are not marked as Exclusive.
6.
Simplify. Use a System DSN that uses a local drive letter. Move the database to the local drive if necessary to test.
7.
The "other user" might be Visual InterDev. Close any Visual InterDev projects that contain a data connection to the database.
8.
This error may also occur when accessing a local Microsoft Access database linked to a table where the table is in an Access database on a network server. In this situation, please refer to the following article in the Microsoft Knowledge Base for a workaround: