ADO.NET :: Open And Close Connection?
Mar 23, 2011When should i open and close the database connection.and which are best data classes (for e.g dataset, datatable etc) should i use when connection is open or close.
View 3 RepliesWhen should i open and close the database connection.and which are best data classes (for e.g dataset, datatable etc) should i use when connection is open or close.
View 3 RepliesWhen I'm using this to open Connection to DB,
Do I need to Close it at the end?
Or by using it, it close by itself?
using (SqlConnection cnn = new SqlConnection(connectionInfo))
I'm using Visual Studio 2008, and my database is SQL Server 2000.
I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.
But when I click OK, I get the error:
Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.
I previously used a datasource and a connection string to connect to my database on sql server and all orked fine. The connection string was saved in my web.config file and is: ....
View 1 RepliesI have a page where I load a couple of dropdown lists from the database (DB). I do this by calling a general function that connects to the DB and gets the data to the dropdownlist. This means that I can have three queries to the DB while rendering one page.
should I close and dispose the sqlconnection, sqlcommand and sqldatareader at the end of this function?
Would it be faster if I left it open for the next call, if you get what I mean, or is it best to close and dispose it every time?
we are using WCF web service. My job is to create the client WCF service.
Sample 1
try
{
Serviceclient client = new Serviceclient();
client.GetOrders();
[code]...
Which the best place to close the connection. Is it in Server side or Client side?
Our site was under Slow HTTP POST DOS attack recently. It's when your server receives a lot of incoming connections and keep them for long time because the sender sends information very slow and server cant serve real users' request - denial of service.
So I decied to reject such POST requests:
void Application_BeginRequest(object sender, EventArgs e)
{
if ( _my_condition_here_ )
{
_reject_the_request_by_dropping_connection_
}
}
The problem is that I can't drop the HTTP connection in asp.net:
Response.End(), throw new Exception(), even Thread.CurrentThread.Abort()
don't close the connection. It waits while sender sends all the fake data, then answer to it with '500 server error' or something. The slow POST attack still will be successful in this case.
How can I just drop the connection?
How to close connection in web.config?
View 5 Replieshow to use global asax to close the opened connection when user logout from the application?
View 9 RepliesThe reason this question came up, is because if I run my website application with a SQL Server data store, and I terminate the browser (terminating the session), I try to open up SSMS to edit the DB. But I can't access the database because I believe there is still an open connection, even after application termination.
Is it recommended to close the database connection upon session/application closing? Or am I way off on what I'm thinking could be the problem?
I made a site www.hediyelikdukkani.com and I added the site to goole from web masters tools. But google doesn't index my web site. When I test my site how the google see from Test like a Google bot from web masters tools it says that
[Code]....
does DbCommand.Dispose() automatially close the database connection?
Here is my code:
Database db = DatabaseFactory.CreateDatabase("DBIS");
string sqlCommand = "procUIBillingAdjustmentsCreditInvoicedSegment";
DbCommand dbCommand = db.GetStoredProcCommand(sqlCommand);
DataSet ds = new DataSet();
[Code]....
I am using a adapted version ofhttp://www.mikesdotnetting.com/Article/45/Programmatically-accessing-data-from-DataSource-controlsDon't we need something like a closing-routine / close connection command after getting data from the database?If yes: What is the correct closing command?
View 2 RepliesIs this necessary to open and close connection when i am using SqlDataAdapter and DataSet to get data from from table from databse in sql server? Which one will be better to use in the following code. Code1 or Code2.
Code: 1 With open and colse connection
public DataSet GetFAcadSlidingImage()
{
SqlConnection con = GetConnection();
cmd = new SqlCommand("Pro_GetFAcadSlidingImage", con);
cmd.CommandType = CommandType.StoredProcedure;
[Code].....
Code:2 Without open and colse connection
public DataSet GetFAcadSlidingImage()
{
SqlConnection con = GetConnection();
cmd = new SqlCommand("Pro_GetFAcadSlidingImage", con);
cmd.CommandType = CommandType.StoredProcedure;
[Code].....
[Code]....
I can check whether username exists or not successfully but not for email. any ideas why it isn't working? Error message was that i did not close my connection. using System;
Is it mandatory to close database connection in enterprise library 4.1?
View 1 Repliesdoes anyone have any working code that uses javascript to open and close a cpe when the CPE is in a masterpage? It seems like the javascript never is able to find the CPE when it is on a master page. I have an DropDownList on the page and when certain items are selected, i want to collapse or expand when others are selected. It seems to work fine on a regular page, but not when it is a page nested in a master page. It is adding a suffix to the CPE and javascript is unable to find it.
[code]....
In PageA, there is a button to open a crystal report. I want to add a HTML button into crystal report to close report(browser) and back to PageA. How to use javascript to do this job?
View 1 Repliesbelow i am using dataset and con.oen and close. but i read that dataset doesnt require con.open/close since it does that autoatically.now my project is complete and implemented with opens and closes for datasets.here is code for all datasets are liek this:-
[Code]....
1)so is what i have done a bad coding practise?2)will it make the application pool to hang?3)should i remove all open/close from the files?
Dim ds As DataSet = New DataSet
con.Open()
Dim dad As SqlDataAdapter = New SqlDataAdapter(cmd)
[code]...
If I have 5 CollapsiblePanelExtenders on page and I want open second one I want close the first one and then open second one...How??
View 2 RepliesI am tring to open the panel with clicking linkbutton and to close the same panel using that link button .How can i write close and open in one event .
View 4 RepliesI'm using 3 diff websiteA,B.C. Im logging in A and accessing B,then logging out it means B has to close;then the redirection is A.likewise C to B.
View 2 RepliesI deployed my MVC app to IIS 7.0 and I keep getting the following error; ExecuteNonQuery requires an open and available Connection. The connection's current state is closed I dont get this with the app locally on my machine. Where could this error be occurring??
View 2 RepliesIn PageA, there is a button to open a crystal report. I want to add a HTML button into crystal report to close report(browser) and back to PageA. How to use javascript to do this job?
View 1 RepliesI am opening a thickbox in aspx page using following line
<a
class="thickbox"
href="BBBuyResult.aspx?keepThis=true<%=getPassResult()%>&TB_iframe=true&height=600&width=800" title="Buy
Now"><b>Buy Now</b></a>
then in server side scripting i need to close this page and redirect parent to some other page i use this code
Page.ClientScript.RegisterStartupScript(
Me.GetType(),
"closeme",
"window.parent.tb_remove();window.parent.location='https://shop.netcentral.co.uk/order/';",
True)
this is not working, when I use inlinetab in thickbox i can close opened div using self.parent.tb_remove()