DataSource Controls :: Best Way To Close Or Dispose (All Ado.net Object)?
Jan 4, 2010
what is the best to close or dispose all the ado.net object
eg:datareader.close(); or sqlcommand.Dispose();
if programs hangs in the middle(because of error), then how to close all the ado.net object so there will be no memory leak
View 5 Replies
Similar Messages:
Feb 28, 2011
I 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?
View 6 Replies
Mar 23, 2011
There's a problem, wherein a XML Document.Save is resulting in the error the process cannot access the file, because it is being used by another process or the statement an Invalid XML Document.I think it's because I do not dispose the XML Document object after it's operation is complete.Is it possible to do this.Is there a workaround?
View 2 Replies
Nov 9, 2010
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]....
View 4 Replies
Jul 6, 2010
project was clean after release build, but when i ran "Run Code Analysis" i got 256 errors. the error below is one of them. will be great help. if anybody can explain, what is the meaning of this error?
[code]...
View 1 Replies
Apr 16, 2010
I have created my custom MembershipProvider. I have used an instance of the class DBConnect within this provider to handle database functions. Please look at the code below:
public class SGIMembershipProvider : MembershipProvider
{
#region "[ Property Variables ]"
private int newPasswordLength = 8;
private string connectionString;
private string applicationName;
private bool enablePasswordReset;
private bool enablePasswordRetrieval;
private bool requiresQuestionAndAnswer;
private bool requiresUniqueEmail;
private int maxInvalidPasswordAttempts;
private int passwordAttemptWindow;
private MembershipPasswordFormat passwordFormat;
private int minRequiredNonAlphanumericCharacters;
private int minRequiredPasswordLength;
private string passwordStrengthRegularExpression;
private MachineKeySection machineKey;
**private DBConnect dbConn;**
#endregion
.......
public override bool ChangePassword(string username, string oldPassword, string newPassword)
{
if (!ValidateUser(username, oldPassword))
return false;
ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, newPassword, true);
OnValidatingPassword(args);
if (args.Cancel)
{
if (args.FailureInformation != null)
{
throw args.FailureInformation;
}
else
{
throw new Exception("Change password canceled due to new password validation failure.");
}
}
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@applicationName", applicationName);
p[1] = new SqlParameter("@username", username);
p[2] = new SqlParameter("@password", EncodePassword(newPassword));
bool retval = **dbConn.ExecuteSP("User_ChangePassword", p);**
return retval;
} //ChangePassword
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
......
ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
if ((ConnectionStringSettings == null) || (ConnectionStringSettings.ConnectionString.Trim() == String.Empty))
{
throw new ProviderException("Connection string cannot be blank.");
}
connectionString = ConnectionStringSettings.ConnectionString;
**dbConn = new DBConnect(connectionString);
dbConn.ConnectToDB();**
......
} //Initialize
......
} // SGIMembershipProvider
I have instantiated dbConn object within Initialize() event. My problem is that how could i dispose off this object when object of SGIMembershipProvider is disposed off. I know the GC will do this all for me, but I need to explicitly dispose off that object. Even I tried to override Finalize() but there is no such overridable method. I have also tried to create destructor for SGIMembershipProvider.
View 2 Replies
May 4, 2010
When 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))
View 2 Replies
Feb 8, 2010
I'm getting "This SqlTransaction has completed; it is no longer usable" exception when try to commit my transaction after sqlreader is close.Here is the code sample
[Code]....
...so when I get to commit the transaction it raises the mentioned exception: "This SqlTransaction has completed; it is no longer usable". I have also noticet that Command.Transaction becomes NULL after reader.Close()My question is: Can I use SqlDataReader and SqlTransaction ? Maybe to use BeginExecuteReader and EndExecuteReader ?
View 3 Replies
Apr 20, 2010
im tryin to create a login form.
and am receiving the following error:
Object reference not set to an instance of an object
[Code]....
and heres my aspx page:
[Code]....
Stored procedure:
[Code]....
View 2 Replies
Feb 17, 2010
On DBML I have two entities as Parent, Child. I am trying to assign Child class properites in a Parent.
[code]....
I am getting the following Error:
Cannot access a disposed object.
Object name: 'DataContext accessed after Dispose.'.
View 2 Replies
Jul 27, 2010
[code]....
i'm having trouble because when it has no return value i get the error
Object reference not set to an instance of an object.
View 10 Replies
Jan 24, 2010
im using a sqldatasource and i want it to query a table chosen from a dropdownlist, so i wrote the following in the .cs file
[Code]....
im recieving this error msg: Object reference not set to an instance of an object (pointing to the line containing the select command)
i don't know what's the problem, i tired a hard-coded statement and it worked fine!
View 2 Replies
Mar 23, 2010
Is it mandatory to close database connection in enterprise library 4.1?
View 1 Replies
May 26, 2010
I am adding rows to table and setting value row/cell value, but for datetime field it is giving me error
Object reference not set to an instance of an object.
Initially I am adding a column to table as
table.Columns.Add("Upload Date",
typeof(DateTime));
Then I assigning value to row as
row["UploadDate"] = result["Execution Date"].ToString();
As I have I also null or empty value in the "Execution Date" field .
View 3 Replies
Mar 26, 2010
On my web page, I've a shared object with initiate (open session) on the load event.
I would like to close this object when the page is close and invoke a close session method.
how do I use the event to do this?
View 2 Replies
Apr 1, 2011
I have a System.Data.Linq.DataContext object and need to know the proper way of closing it out before it goes out of scope in order to prevent the following error when making a bunch of database changes:
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Can I just call obj.Dispose() or do I need to call obj.Connection.Dispose() or obj.Connection.Close()?
I guess what I want to know is will calling obj.Dispose() end up executing the functionality in obj.Connection.Dispose() and obj.Connection.Close(). The MSDN documentation that I found on these functions does not have this information (at least I didn't see it - I could have mistakenly overlooked it).
View 3 Replies
Mar 10, 2011
i have problem white Object datasource. i have a multi-tier Application that include common layer ,DAL Layer,business logic and persantation layerwhen i add a object datasource to my page, it bring me only common layer classes . but i want use bisuiness layer classes what do i do ?
View 1 Replies
Oct 27, 2010
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
View 2 Replies
Aug 9, 2010
This is the first time I have been working on databases and I am trying to insert data using an object datasource but no data is being inserted and no exception is thrown. I'm not sure where I am going to wrong. I am putting user data into session variables and inserting the session variables into the dataacess class layer and have a try and exception but nothing being thrown. Any help would be really appreciated because I don't know even where to start looking with this or how I can get the error to be thrown. Please see some of my code below to give an idea of what I am doing
Object Access Class
public void InsertCarPolicyHolder(PolicyHolderClass ph, CarInsuranceOptions options)
{
[code]...
View 2 Replies
Jan 17, 2010
I have a Public Sub listed in a class file that I am using to store Select, Update,etc...methods for an Object Datasource. When I attempt to configure the datasource, the Class appears as a business object, but the sub within the class is not available for method selection. (It does not appear in drop down list in wizard.)
The sub exists, so where is a good place for me to start looking for a fix? I have part of the class file listed below:
[Code]....
View 7 Replies
May 3, 2010
Traditionally with an Object Data Source, the wired up class will have its public properties available for binding (i.e. Gridview columns, etc.) which works well. But what if one of my wired up business objects has a property that is an object itself; can I drill down to a property on that object property and still use it?
So in additiona to the traditional:MyBusniessObject.OrderID...I want to use:MyBusniessObject.Customer.NameID
Your 1st response might be to just wire up the 'Customer' class, but I need properties both on 'MyBusinessObject'and 'Customer'. I do not think this can be done, as the ODS will not display properties on an object instance property. I have tried manually typing in the drilled down value as well, but that wasn't a success either.
View 4 Replies
Aug 25, 2010
I'm getting the old "Object reference not set to an instance of an object" error on this code:
nonqueryCommand.Parameters.Add("@comment", SqlDbType.VarChar, 500)
nonqueryCommand.Parameters("@comment").Value = CType(FormView1.Row.FindControl("CommentsLabel"), TextBox).Text
"CommentsLabel" is a textbox, despite it's name (and I've tried the CTYPE ot Label too).
View 3 Replies
Mar 5, 2010
have an object datasource that calls a web method to retrieve a set of data. That web service resides on another remote server with Windows Authentication enforced. How do I pass in the credentials required for the authentication from my web application? My code is as follows:
[Code]....
View 7 Replies
Dec 16, 2010
I have website which runs multiple threads. When user close the browser but threads are still running. How to kill/stop all thread in asp.net on browser close.
View 2 Replies
Jun 22, 2010
I am developing on application in that i have taken one list box and getting data to it using an object source.up to this stage it is fine.I need to compare these value what i get into list box and need to represent data in to a report viewer ..how to get these values from objectsource.i m new to c# i placing the code.
[Code]....
View 1 Replies