|
I don't really understand your question, but I'll try to shed some light.
If you are building a multi-threaded application (like an ASP.NET web application), then each thread needs to have it's own connection object when working with the database. If you are trying to use the same connections for all threads, only one thread at a time can access the database, and that would indeed be harmful for the scalability.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
static classes can only contain static members.
These classes cannot be instantiated using new and are automatically loaded by the runtime.
If the static methods refers to static variables they are not thread safe.
«_Superman_»
|
|
|
|
|
DineshSharmain wrote: no. of users are accessing one static method of static class.....that performs any operation like data insertion, update, deletion and fetching from database.....
There is no harm in using it when the static method is not using any shared variables. See the following code
public static class Foo
{
public static void FooMethod(string a,string b){
....
}
} In the above example, FooMethod is safe as it is not using any shared objects. Whenever you use FooMethod , you will have separate copy of variable a and b .
public static class Foo
{
private static string FooVariable = "";
public static void FooMethod(){
}
} Above given code is not safe as static variable(FooVariable) is shared across multiple threads. Read about thread synchronization techniques.
|
|
|
|
|
Thanks for your reply.....
my problem is not related to database....its related to performance & scalability of static classes.
code is as follows -
static public class TempExample
{
static public bool GetCombo(object a, out DataSet dsAccountClass, string strClassType)
{
IDBHelper intfDBHelper = DBClient.GetDBHelper();
dsAccountClass = new DataSet();
IDataParameter[] arParms = intfDBHelper.CreateDBParamsArray(2);
arParms[0] = intfDBHelper.CreateNewDBParam("ID", SqlDbType.NVarChar, 6);
arParms[0].Value = a.strA;
arParms[1] = intfDBHelper.CreateNewDBParam("ClasificationType", SqlDbType.NVarChar, 1);
arParms[1].Value = strClassType;
try
{
using (IDbConnection connection = DBClient.GetConnection(a.strSystem))
{
intfDBHelper.FillDataset(connection, CommandType.StoredProcedure, "p_GetSpConditionCalssCombo", dsAccountClass, new string[] { "dt_ProductClassID" }, arParms);
}
if (dsAccountClass.Tables[0].Rows.Count == 0)
return false;
return true;
}
catch (Exception ex)
{
throw DBClientUtils.GetDBErrorMessages(ex, a.strUser);
}
finally
{
dsAccountClass.Dispose();
}
}
}
Multiple user will be accessing this class without creating an object so what will happen if 100 users are trying to access the same method of class at the same time.
Dinesh Sharma
|
|
|
|
|
DineshSharmain wrote: its related to performance & scalability of static classes.
Static classes will be invoked when any of the members are accessed for the first time and it will be available in memory until the application domain unloads.
DineshSharmain wrote: if 100 users are trying to access the same method of class at the same time
Nothing will happen. I reiterate, if your method is using another static variables, then you need synchronization mechanisms to ensure one thread will modify it at a time. If it is not using any static variables, your method is safe.
|
|
|
|
|
Thanks Navneet
wat about the code....I have given....is this thread safe
may i get any deadlock situation in my application due to this ...as m getting if load increase on application so m digging all this.
Dinesh Sharma
modified on Wednesday, January 7, 2009 2:52 AM
|
|
|
|
|
I don't know what is methods DBClient.GetDBHelper() and intfDBHelper.CreateDBParamsArray(2) doing and where dsAccountClass variable is declared. Other than that, I think it is safe.
|
|
|
|
|
Hello Forum
I need to translate an existing application to multiple langauages,
How can i extract all the text strings such as message box messages, text box values etc. so i know what i need to translate.
Please Help
|
|
|
|
|
belzer wrote: How can i extract all the text strings
Open the files and read
only two letters away from being an asset
|
|
|
|
|
You need to put the text into resx files for each language. Use ResourceManager class to access it. This[^] article will help to get started.
belzer wrote: How can i extract all the text strings such as message box messages, text box values etc. so i know what i need to translate.
I am not sure I got you. Do you want to extract the text which is displaying currently in message boxes and other labels? If yes, it is not possible to do programmatically.
|
|
|
|
|
1. Read the code files, or
2. Write a code to read code files and return the text between double quotes, file name and line number.
The word "politics" describes the process so well: "Poli" in Latin meaning "many" and "tics" meaning "bloodsucking creatures."
|
|
|
|
|
If you have the source code, then you can use the ResourceManager class. If you don't, and it is a .Net application, then you could probably look into System.Reflection and an IL reader class from this site to get the intermediate code, then look for all instances of the ldstr instruction, and capture anything in quotes after it
|
|
|
|
|
is there anyway to add resource at runtime ?
I want to merge some images and files with application...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: is there anyway to add resource at runtime ?
You want to embed some resources to the assembly? If yes, I don't think it is possible unless you recompile the assembly.
|
|
|
|
|
yes but no way at all ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I am not sure. BTW, why you need to do this?
|
|
|
|
|
Single exe, i know its not good but i need
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Generally speaking, modifying a compiled assembly at runtime is a bad idea. You run the risk of corrupting the assembly. Beyond that, many virus scanners keep track of file sizes for executable type files on a system. If the size of an executable changes, virus scanners identify that as a virus (since they usually tack themselves onto executable packages, modifying their size). Merging resources into an executable is a pretty bad idea, and even if it were possible (its .NET...so it probably is), I wouldn't recommend it.
|
|
|
|
|
Hi Guys,
Ive tried to do a simple caching application and have traced/debugged it, however it does not seem to store the datatable into the cache.
No matter how many times I load it it always retrieves the data from the Database instead of the cache after refreshing the page. Could someone interpret my code, Cheers.
public partial class Caching_ApplicationCaching : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string query = "SELECT FIRSTNAME, LASTNAME FROM CUSTOMERS";
DataView source = (DataView)Cache["Client"];
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
{
if (source == null)
{
conn.Open();
SqlCommand command = new SqlCommand(query, conn);
SqlDataAdapter adapter = new SqlDataAdapter(command);
command.CommandType = CommandType.Text;
adapter.Fill(ds, "Customers");
Cache.Insert("Client", ds);
foreach (DataRow item in ds.Tables["Customers"].Rows)
{
string Firstname = item["FirstName"].ToString();
DropDownList1.Items.Add(Firstname);
source = new DataView(ds.Tables["FirstName"]);
Cache["Client"] = source;
}
}
else
{
DropDownList1.DataSource = source;
DropDownList1.DataBind();
}
}
}
}
|
|
|
|
|
CrimeanTurtle2008 wrote: Cache.Insert("Client", ds);
Here you are putting the DataSet in the cache, which is pointless as you later overwrite it.
CrimeanTurtle2008 wrote: source = new DataView(ds.Tables["FirstName"]);
Cache["Client"] = source;
Here you try to read a table named "FirstName" from the DataSet, but there is no such table so you get an empty DataView.
Then you replace the value in the cache with the empty DataView. For some reason you do this over and over, once for every row in the table "Customers", but it doesn't help how many times you do it as long as there is no DataTable.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
How would I remedy this?
Would I need to insert the dataset into the cache after declaring what the
source is?
|
|
|
|
|
CrimeanTurtle2008 wrote: Would I need to insert the dataset into the cache after declaring what the
source is?
You already insert the DataSet into the cache. If you have a cached DataSet then use that rather than what ever it was you were attempting to insert.
|
|
|
|
|
CrimeanTurtle2008 wrote: How would I remedy this?
You store in the cache what you want to fetch from the cache.
CrimeanTurtle2008 wrote: Would I need to insert the dataset into the cache after declaring what the
source is?
Why would you want to insert the DataSet in the cache? Aren't you trying to store a DataView?
By the way, why are you trying to store a DataView? Why not store the DataTable?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hmm ok, I will tinker with what you recommended ,Thanks.
|
|
|
|
|
You can probably make this simpler and more maintainable:
public partial class Caching_ApplicationCaching : Page
{
const string QUERY = "SELECT firstname, lastname FROM customers";
const string CACHE_KEY = "Client";
protected void Page_Load(object sender, EventArgs e)
{
DataTable source = GetCustomersTable();
DropDownList1.DataSource = source;
DropDownList1.DataTextField = "FirstName";
DropDownList1.DataBind();
}
private DataTable GetCustomersTable()
{
DataTable source = (DataTable)Cache[CACHE_KEY];
if (source == null)
{
source = PopulateCustomersCache();
}
return source;
}
private DataTable PopulateCustomersCache()
{
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
using (SqlCommand command = new SqlCommand(QUERY, conn))
{
conn.Open();
command.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "Customers");
DataTable dt = ds.Tables["Customers"];
Cache.Insert(CACHE_KEY, dt);
return dt;
}
}
}
}
|
|
|
|