473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# code for access denied of file at time of uploading and importing in sql table

5 New Member
Hi I have an error while uploading file and then importing it into my sql table


The process cannot access the file 'c:\inetpub\www root\FlowLine\E xcel File\Fan_Detail s.xls' because it is being used by another process

Now Some times its run successfully, i don't no how but somtimes it gives error,

I figure out there is security issue of the folder where its storing the file,
But i had given all right to user there

code is

string fullPath;
string Path;

public void fetch_file_path ()
{


path = fup_path.Posted File.FileName;

path = System.IO.Path. GetFileName(pat h);

fullPath = Server.MapPath( "Excel File" + "\\" + path);
if (fup_path.Poste dFile.FileName != "")
{


fup_path.Posted File.SaveAs(ful lPath);
}

}


//**********Impor ts Xls file in Sql table t_fan_details** *************** ***********
public void import_xlsFile( )
{
fetch_file_path ();
try
{
utility dut_count = new utility();
int table_count;
string sqlStr = "select count(*) from t_fan_details ";
table_count = dut_count.iscou nt(sqlStr);


// Create Connection to Excel Workbook
string strConnection = @"provider=Micr osoft.Jet.OLEDB .4.0;data source=" + fullPath + "; Extended Properties=Exce l 8.0;";
OleDbConnection connection = new OleDbConnection (strConnection) ;

if (connection.Sta te == ConnectionState .Closed)
{

connection.Open ();
}

OleDbCommand command = new OleDbCommand("s elect f_Volume,f_Tota l_Pressure,f_St atic_Pressure,f _outlet_type,f_ Density,f_power _correction,f_d uty_point_toler ance,f_Total_Ef feciency,f_Stat ic_Effeciency,f _rpm,f_Fan_Powe r,f_Motor_Power ,f_Shaft_Power, f_Velocity,f_du ty_point FROM [Data$]", connection);

// Create DbDataReader to Data Worksheet

OleDbDataReader dr = command.Execute Reader();
int count=0;
while (dr.Read())
{
count += 1;
}

// SQL Server Connection String
Source=localhos t;database=demo ;user id=sa;pwd=sa";

// Bulk Copy to SQL Server

SqlBulkCopy bulkcopy = new SqlBulkCopy(Con figurationManag er.AppSettings["connectionstri ng"]);


bulkcopy.Destin ationTableName = "t_fan_details" ;

// bulkCopy.WriteT oServer(dr);
bulkcopy.WriteT oServer(dr);

bulkcopy.Close( );
if (!dr.IsClosed)
dr.Close();
int selected_record =table_count + 1;

sqlStr = "select max(f_sno) from t_fan_details where f_sno in (select top " + selected_record + " f_sno from t_fan_details order by f_sno desc)";
utility dut_max_fsno = new utility();
int fsno = dut_max_fsno.is count(sqlStr);
Int64 f_fantype_sno, f_model;
f_fantype_sno=C onvert.ToInt64( Request.QuerySt ring["id"]);
f_model = Convert.ToInt64 (Request.QueryS tring["model_sno"]);

int i = 0;
for (i = 0; i < count; i++)
{
sqlStr = "update t_fan_details set f_fantype_sno=" + f_fantype_sno + ", f_model_sno=" + f_model + " where f_Sno="+fsno+" ";
utility dut_fandetails = new utility();
dut_fandetails. executeSQL(sqlS tr);
fsno = fsno + 1;
}
Response.Write( "Data Imported From Xls file");
if (connection.Sta te == ConnectionState .Open)
connection.Clos e();


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

protected void btn_upload_Clic k(object sender, EventArgs e)
{
import_xlsFile( );
}
Dec 15 '07 #1
0 1612

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2938
by: Steve | last post by:
Hi, Yesterday I signed up for another dedicated linux server with the hosting company I use and I am having problems getting MySQL 4.1.3 working on it. I've tried just about everything I can think of to login via the MySQL client but get a variation of the following error every time: ERROR 1045 (28000): Access denied for user...
1
8163
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time fields. 177 102003 16:43:12 102003 18:43:12 6OAG0ADP Y 0000 0000 0000 0000 61930 4HGA800 165 102003 17:43:12 102003 18:44:12 6OAG0ADP Y 0000 0000...
2
3589
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records that are "dirty" i.e. the field contents do not comply with the expected format (date/time) and they end up in a seperate table of import errors....
1
2851
by: HNguyen | last post by:
Access denied error while uploading a file to a web server. I am getting the following error while trying to upload a file to our web server: Error: Access to the path "e:\web\...\DBConnection.txt" is denied. We are working with IIS 6.0 on Windows 2003 Server running .NET Framework 1.1. To perform the upload we are using...
2
457
by: HNguyen | last post by:
Hi all, I have a problem with the access to the folder for uploading the file into that folder by using ASP.NET program. The error message was : "Access is denied ..." to the location I save the file. This problem didn't happen when I ran my ASP.NET program with my localhost server on my personal computer at home. The problem happened in...
12
3073
by: Ron Weldy | last post by:
I have a test server runinng 2003/IIS 6 with a mixture of asp and asp.net files. On my workstation I have a share set up to the folder where the web files reside. I am just doing quick and dirty asp editing (like I used to be able to do with 2K/IIS5) where I use VS.NET, open an asp file, make changes, save and refresh my browser. Problem...
5
3156
by: hharriel | last post by:
Hi, I am hoping someone can help me with an issue I am having with excel and ms access. I have collected data (which are in individual excel files) from 49 different school districts. All districts have used the same excel template and populated the same 32 data fields (columns). I created one large excel file from all 49 files which gives...
1
3096
by: puremetal33 | last post by:
I have worked very little with Access and have hit a snag. My task right now is to import the data from a spreadsheet into an existing table in an Access database. I edited the .xls file so that fields are laid out the same L-R and made certain that the data is the same in both the .xls file and the table it is to be imported to have the...
6
4108
by: passionateforjava | last post by:
Hi All, I am using struts application wherein I need to import file for some purpose.I have used input type="file" for the same which goes like: <input type="file" id="uploadFile" name="uploadFile" size="50"> I have the import button on which I have used onClick event to call javascript function submitValues() used to validate all the fields...
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7461
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.