Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a windows application with c sharp and sql2008 my windows application works fine but it is generating error if left idle for long time and then try to do any operation. Application needs to run whole day, anybody have any idea how to remove this condition or have any idea about that problem, is it connection timeout problem.

There is sample of my code m using microsoft liabrary for database operations
static string str = ConfigurationSettings.AppSettings["connection"].ToString().Replace("|DataDirectory|", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
private Database objDatabase = new SqlDatabase(str);

Then i m using objDatabase like this
C#
public DataTable SelBarcodeInfo(clsDALSales obj) 
{ 
    ds=objDatabase.ExecuteDataSet("spSelBarcodeDetailByBarcodeNo",bj.intBarcodeNo);  
    return ds.Tables[0]; 
} 


All working well
Posted
Updated 4-Dec-12 0:25am
v4
Comments
Simon_Whale 4-Dec-12 4:06am    
how are you handling your database connections?
is a connection left open while the application is open? do you open / close the database connection when needed?
is it timing out while you are running a long process that actually doesn't require database access at the start of the process?
NarendraSinghJTV 4-Dec-12 4:11am    
simon thanks for quick reply, i m using microsoft enterprise library for database operations. problem occurs when we leave application idle for long time.

Not very sure, why you would like to keep the SQL Connection open. Ideallistically you should NOT keep SQL connection open. That's where all disconnected architecture (dataset) came in to existence.

However, considering you may have some "valid" reason for doing what you are trying to do, you need to set connection pooling in your app.config.
Check http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx[^]

Hope that helps
Milind
 
Share this answer
 
Comments
NarendraSinghJTV 4-Dec-12 4:18am    
Milind thanks for your suggested link, but i m using enterprise liabrary of microsoft and i didnt used connection.open or connection.close in my code.
MT_ 4-Dec-12 4:27am    
Agree Narendra. But this is about connection pooling and to control that you need to have correct connection string. No matter what you use for connection, YOU are providing the connection string ...right?
NarendraSinghJTV 4-Dec-12 4:37am    
yes milind you are right, my connection string is

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbSoft.mdf;Integrated Security=True; User Instance=True"
NarendraSinghJTV 4-Dec-12 4:49am    
any idea what is wrong with my connection string or i have to update anything in my connection string
MT_ 4-Dec-12 5:53am    
Can you add what is the value of connection string in the app.config?
As you haven't really given us any code snippets to help I would suggest that you have a read through these articles

ConnectionsStrings.com/SQL2008[^]

SqlConnection.ConnectionString Property[^]

As the only thing I can suggest is that you make sure that your connection string is configured properly to begin with, If this is not the problem please can you update your question with a sample of your code
 
Share this answer
 
Comments
NarendraSinghJTV 4-Dec-12 4:34am    
There is sample of my code m using microsoft liabrary for database operations

static string str = ConfigurationSettings.AppSettings["connection"].ToString().Replace("|DataDirectory|", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
private Database objDatabase = new SqlDatabase(str);

Then i m using objDatabase like this

public DataTable SelBarcodeInfo(clsDALSales obj)
{
ds = objDatabase.ExecuteDataSet("spSelBarcodeDetailByBarcodeNo", bj.intBarcodeNo);
return ds.Tables[0];
}

All working well
Simon_Whale 4-Dec-12 4:44am    
does the query take a long time to execute?
NarendraSinghJTV 4-Dec-12 4:48am    
no but when i re-run the same query after long time delay it generate error and that is the main problem.
Simon_Whale 4-Dec-12 4:57am    
you need to look then at when you open and close the connection to the database, as ideally you need to keep database connections open for the intended operation.

i.e.
public DataTable SelBarCodeInfo(clsDALSales obj)
{
using( Database objDatabase = new SqlDatabase(str)) //this will dispose of the connection when completed.
{
ds = ObjDatabase.ExecuteDataSet("spSelBarcodeDetailByBarcodeNo", obj.intBarcodeNo);
}

return ds.tables[0];
}
Set ConnectTime out in connection String or connection property
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900