Web Forms :: Writing A Log In Xml File Or Insert Query In Database?
Feb 20, 2010
i want to maintain a log of the visitors for a website.. the number of visitors is fix approximate (800), but i have to maintain the record of each visit page wise like page Id, time visited, user id. i am doing it using a database as it was .
i was asked to use a insert query on every page ,(ie each time user visits a page write the log to database), but i dint like the idea.. of making server trips every time the user visits a page and also we have a seperate database server. I had a idea of using XML.. but which is the best way performance wise writing a log in Xml file or insert query in database?
i have a problem executing an insert query. whenever i try to insert i have an exeption telling me it cant execute because a record needed in another table; where i select a value form that other table according a listbox, and then insert it into this table. here is a sample of my code:
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|emp2.mdb");
int a = 0; conn.Open(); string sqlcmd = "select id from nationality where descreption = '" + DropDownList1.Text + "'"; OleDbCommand readNatCmd = new OleDbCommand(sqlcmd, conn); OleDbDataReader readerNat = readNatCmd.ExecuteReader(); while (readerNat.Read()) { a = readerNat.GetInt32(0); } readerNat.Close(); conn.Close(); string saveEmpcmd = @"insert into employee " + "(nationality) " + "values (@nationality)"; OleDbCommand objCmd = new OleDbCommand(saveEmpcmd, conn); objCmd.Parameters.AddWithValue("@nationality", a); conn.Open(); objCmd.ExecuteNonQuery(); conn.Close();
now, the form executes with no errors, but it catches an exeption caused by the ExecuteNonQuery funtion; here it is in details:
System.Data.OleDb.OleDbException: You cannot add or change a record because a related record is required in table 'nationality'. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at Default2.Button1_Click(Object sender, EventArgs e) in c:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesempDefault2.aspx.cs:line 305
when i remove the relation between the tables, the exeption isnt catched anymore, but the value stored in the employee table is 0 how can i solve this?
Spent ages trying to get this right but am struggling now. I have a list box and textbox, I can happily enter Email addresses into the textbox which are saved into a text file and populated in a list box. I want to be able to select a list item and delete it, along with it's record in my text file. I was going to do it by on the delete list item / button click, it delete's the text file and then writes and a new one with the remaining list items in the list box. Unfortunately it's re-writing the file but either not including the remaining list items. Here's some examples of what I've changed and what populates the text file:
StreamWriter1.WriteLine(Addresses.Items); - System.Web.UI.WebControls.ListItemCollection StreamWriter1.WriteLine(Addresses.Text); - A blank line?!?
The code is below. The reason I wouldn't allow the user to delete the first list item is because I thought the code was working ok but for some reason putting in a blank line to start with, and if I deleted the line it'd delete all file content. No, I don't know why I thought that either.
[Code]....
where I've gone wrong? I've not actually slept since I woke up at 8am yesterday. It's now 11am... today.
i have a "Users today" function that i am trying to work on, i have all the tables set up, and a TimeStamp column, i would like to know how i could get all the users that appeared, but for that day only.
So i used the select statement, but then when i tried to add into query, filtering, i tried using the DateTime.Now, but it only got the users specific to that date, hour, and second.
Based on this piece of code, I want to do exactly like this demonstration. However, correct me if I'm wrong but if two or more users somehow simultaneously access the web page at the same precise nanosecond in time, then wouldn't we have a race condition? So is this piece of code valid? How would I correct this to make it thread safe?
i have a excel file in which "PuNumber,MachineNo,MachineName,StartDateTime,EndDateTime,WorkOrder,RescheduleInterval,Description ,ACT CODE,ACTIVITY DESCRIPTION" are column. WorkOrder is Primary key. we have multiple value of " ACT CODE, ACTIVITY DESCRIPTION" of one work order. i want to store this data into two table one is shcedule table and another in activity table. shcedule table has this column "PuNumber,MachineNo,MachineName,StartDateTime,EndDateTime,WorkOrder,RescheduleInterval,Description " work order is primary key. and Activity table has three column ACT CODE, ACTIVITY DESCRIPTION and WORKORDER " act code and workorder is primark key.
I am using more than one files to read and write to the server. Suppose during writing or reading any of files gets error the already stored files need to be rollback or removed from storing.So that the user agin try to write without error. Simply the all of the files need to be stored into the server without error, of error occurs to any of file none of files need to be read/write
I am trying to create and write a file on a remote server using the below code:
[Code]....
but i am running into issues and getting errors. Below are some tries i have given. My IIS settings are 'Anonymous Access' checked and also 'Integrated windows authentication' checked.
a. As i understand asp.net site would run using ASPNET account, i tried giving full permission to ASPNET account to the folder on the remote server (where i want to drop the file). But i am getting this error - "Logon failure: unknown user name or bad password"
b. The other thing i tried is giving full permissions to 'Everyone' to the remote server folder. But i get the same error as above. But when in my web.config i enable impersonation by using: [Code]....
then the error goes away and everything works fine as expected. The file gets dropped to the network share.
why the scenario (a) doesn't work because that should work as if i give ASPNET account full access to the folder, and my website is running under the same account, then it should work.
Also, in the scenario (b), i believe it is using my domain account, as the impersonation is true without specifying any username and password and also the remote server folder has Everyone access to full control. BUT, as a security breach, i cannot use Everyone account to the remote folder. In that case, how can i make this working.
I was also thinking if i can use the virtual directory as the path to the remote folder, something like http://domain.com/remotefolder but dont know how can i use this approach. Can someone pls share some sample code and the configuration.
I'm making an application which takes image from user upload it to server and then perform any image processing like to convert to gray or invert etc.
My problem is this when i did the process on image to gray it or invert then how to write this new file on server or is there any other way so that i would be able to show this (new) image to user and make it downloadable?
In my application i want to share one .txt for read and write among no. of users. in Button click i m writing data in that file and in tick event of Timer i m reading that file, In tick event i m reading that file based on file based cachin means if file have been changed then only i m reading that file but when i have put m application i IIS then i m not able to get updated file.
I have the following subroutine in an asp.net application class. The subroutine writes data to a text file upon application login. My question is that if this function was called at the same time by two different users would it cause any kind of error. Is there a need for a try catch?
Public Shared Sub writeToLogFile(ByVal UserName As String) Dim strLogMessage As String = String.Empty Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt") Dim swLog As StreamWriter strLogMessage = DateTime.Now.ToShortDateString().ToString() " ==> " & UserName If Not File.Exists(strLogFile) Then swLog = New StreamWriter(strLogFile) Else swLog = File.AppendText(strLogFile) End If swLog.WriteLine(strLogMessage) swLog.WriteLine() swLog.Close() End Sub
I keep getting this error when trying to Run or Build my ASP Project. A few details:
I migrated this project from VS 2003 to VS 2008 (C#) It works fine when I successfully compiled it and deployed onto server.I have Plenty of free diskspace available.I have 4 GB Ram and Windows XP So each time I try to build this project, I get the following error.
Error 57 Unexpected error writing metadata to file 'C:InetpubwwwrootProject.IntranetobjTestProject.Intranet.dll' -- 'Not enough storage is available to complete this operation. 'Project.Intranet
I have grid view in ASP.Net 3.5. I need to add multiple blank rows in a gridview and then have to save them in database. How can I do that in most simplest way?
i just cannot work this out... i have a gridview and when a user clicks on a row the checkbox unchecks itself... when the user clicks the row a sqldatasource.update is called from the selectedindexchanged event, problem is when it writes back to the database it writes back every checkbox as unchecked, i want just the row that's selected...
what i can't work out is i've tried putting a where clause in the sqlcommand which is something like where primarykeyID = gridview1.selectedvalue... now it won't write anything back to the database...!!! ... once i take out the where clause, it writes back to every row..!!
I'm fairly new at writing c# with asp.net and thought I'd give writing a custom class for a single file uploader, but Im a bit stuck with it. I get build errors with a few of the items, here's my code:
i have a folder in soultion explore that in folder there are some xml file but when write data in c# in xml file,error Access to the path 'E:YavariTCMS-v3TCMSTCMSMDFXMLXMLFile1.xml' is denied. every i remove propertice readeonly from xml or folder that contain xml file ,next tim reade onl true
How can I insert value in two tables by single sql query because if I'm using two sql query it gives problem me on binding data and connection. Like I have 2 table table 1, table 2 ... In table I'm only save id and name and in other table I'm saving id, time1, time2