by Vahid
29. April 2011 18:00
I was working with Entity Framework and I needed to update a single column of a row in the database. basically I was logging the users visit to a web site (ASP.NET). so first time user lands in the website I create a record in database and keep the id in the session. when user’s session times out I needed to update the row and set the exit time of the user. it sounded a bit difficult to do this with Entity Framework I did it this way and worked pretty well:
public void UpdateVisit(long id, string userId)
{
//id (row id) comes from the user so we create an object and assign the id
VisitInformation visitInformation = new VisitInformation() { ID = id };
try
{
using (var context = new TravIranLogEntities())
{
//Here we attach the object to the context and set the state to unchanged
context.Entry(visitInformation).State = EntityState.Unchanged;
//update the column(s) that you need to modify
visitInformation.UserId = userId;
//Send the informatin back to the Database
context.SaveChanges();
}
}
catch (Exception ex)
{
LogManager.Log("Error in UpdateVisit for user id", ex, LogMode.LogAndEmai);
}
}
by Vahid
12. July 2009 04:51
ever wanted to connect to an oracle database in your .net application (asp.net, windows client ect) but tnsnames.ora file was missing? ok,i just found a solution for this in connectionstrings.com. you can use the following connection strings to connect to an oracle database using both microsoft .net provider for oracle database and odp.net:
.NET Data Provider for Oracle
SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=yourHost)(PORT=yourPort))(CONNECT_DATA=(SERVICE_NAME=yourOracleSID)));uid=yourUsername;pwd=yourPassword;
Oracle Data Provider for .NET / ODP.NET
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;