Close Connections Explicitly
Jan 14, 2008
Hi everybody,
How is it possible to close any open connections from the connection pool explicitly like on the log off page? So when the users log off from the application I want to close all connections that were opened during the use of application.
asp.net forums is the best....
thanks,
Murthy here
View 4 Replies
ADVERTISEMENT
Feb 21, 2008
Hello.
I have a db dal containing the following code:
SqlCommand cmd = new SqlCommand();
cmd.Connection = dbc;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SOME STORED PROCEDURE";
.
.
.
declare some SqlParameters
.
.
.
dbc.Open();
cmd.ExecuteNonQuery();
dbc.Close();
This code, when concurrently running via several threads, yields the following exception:
"The connection was not closed. The connection's current state is open."
My questions are:
1. Why don't .Net allocate another connection from the pool (I try to only concurrently run 2 threads while there are 25 connections in the connection pool) ?
2. How can one explicitly allocate a connection?
3. How do you suggest to solve this problem without a mutex/monitor etc' on the 3 bold lines above and without BeginExequteNonQuery()?
Thank you !
View 2 Replies
View Related
Jan 11, 2008
Problem: Connections to SOAP endpoints never close even if app initiating call was shutdown several days earlier. Create Endpoint statement included at bottom
Questions:
1 Why?
2. Is there a configuration option I need to set?
[1] Client side: Multiple clients from XMLSpy running on XP Pro to WebSphere Process Server running on AIX
[2] Server side:
What is the MS SQL version? SQL Server 2005 SP2
What is the SKU of MS SQL? Enterprise
What is the SQL Server Protocol enabled? Shared Memory | and TCPIP
Does the server start successfully? YES
If SQL Server is a named instance, is the SQL browser enabled? YES
What is the account that the SQL Server is running under? Domain Account
Do you make firewall exception for your SQL server TCP port if you want connect remotely through TCP provider? NO
Do you make firewall exception for SQL Browser UDP port 1434? In SQL2000, you still need to make firewall exception for UDP port 1434 in order to support named instance. NO
[2a] Tool Used to Connect: Multiple clients from XMLSpy running on XP Pro to WebSphere Process Server running on AIX
[3] Platform:
What is the OS version?Windows 2003 SP2
Do you have third party antivirus, anti-spareware software installed? McAfee. Exceptions have been set in accordance with MS SQL Server documentation
ENDPOINT:
CREATE ENDPOINT [TestEndpoint]
AUTHORIZATION [AuthID]
STATE=STARTED
AS HTTP (PATH=N'/SqlSSL/testEndpoint', PORTS = (SSL), AUTHENTICATION = (BASIC),
SITE=N'Win2003.ent.corp.net', SSL_PORT = 443, COMPRESSION=DISABLED)
FOR SOAP (
WEBMETHOD 'PutTestResponse'( NAME=N'[UserDb].[schema].[usp_test]'
, SCHEMA=DEFAULT
, FORMAT=ALL_RESULTS),
BATCHES=DISABLED,
WSDL=N'[master].[sys].[sp_http_generate_wsdl_defaultcomplexorsimple]',
SESSIONS=ENABLED, SESSION_TIMEOUT=10,
DATABASE=N'UserDb',
NAMESPACE=N'http://tempTestEndpoint.org',
SCHEMA=STANDARD, CHARACTER_SET=XML)
View 1 Replies
View Related
Nov 21, 2007
should u always close everys sqldatasource connection string and the dataset associated with it,
if so how do u do that (ie the proper way) and is it possible to to do it in the session area of global.aspx, NEt 2.0 or should it be done when exiting the page containing the data stuff,
also same question for NET 1.0 datasets and adapters and strings,
View 1 Replies
View Related
Jun 4, 2007
Dear all
I created this trigger on a table that i think failed while execution. I tried to modify it and run it again but it seems that i cant do that. If i try and delete the database i also cant - saying that it is still in use. But i am not using it and ther are no other users connected to it. I think the trigger has probably hit a loop and that is holding the link.
To close that i know that a solution would be to restart the SQL server instance but that would be a bit hard since the SQL server where my test database resides is a production server and has few other databases that are important and few users use them.
Is there any way through a SQL statement that there can be forced a delete? Or force close all the connections? Or force close all the processes without actually restarting the SQL server instance.
I have tried all options that were offered on some other forums like forcing it to a single user but even that operation can not be performed saying that the database is still in use.
Thank you so much for all your help and time.
Sincerely
Dan
View 1 Replies
View Related
Jul 14, 2015
In SQL Server Management Studio, it is possible to do the following:
a) In Object Explorer, connect to a particular SQL Server Database Engine, let's call it X.
b) Use that connection to generate many SQL queries, connected to X, in the right-hand pane.
c) In Object Explorer, connect to a particular SQL Server Database Engine, let's call it Y.
d) Use that connection to generate many SQL queries, connected to Y, in the right-hand pane.
e) Close the connection to X, which was created in step (a), from within Object Explorer.
In the right-hand pane, I am now left with a bunch of queries connected to X, and a similar bunch of queries connected to Y. Any quick way to shut all the queries connected to X, but none of the queries connected to Y?
This question can assume real practical importance if server X is a Live Production Server, and server Y is a Test Server, and my next job of the day is to run a change script against server Y....
I have looked for an option in Management Studio to "Close all queries connected to Server X", but haven't found one.
View 6 Replies
View Related
Jul 20, 2005
Just a quick question about connection management. My application willnever need more than 1 or 2 connections about at any given time. Also, I donot expect many users to be connected at any given time. For efficiency, Iwould like to keep connections alive throughout the lifetime of the objectsrequiring them, rather than opening a new connection, executing code andthen closing it again. What is the most efficient way of doing this?Should I perform the open/close or just one open when I create the objectand a close when I dispose of it?
View 1 Replies
View Related
Dec 9, 2014
we have roughly 22 people connected to one database. But after a while, their applications begin to drag due to in and out communication with the server. When i check the active connections on the sql server, some times i see 157 active connections, please how to i set a timeout or connection interval close, so as reduce the heavy load being put on the server. Or how can i automatically close connections when they get higher than 50 connections.
This settings should be sql server 2008 related.
View 5 Replies
View Related
Aug 13, 2007
Hi All,
I would like to restore database using RESTORE DATABASE ... REPLACE command.
If database exists already and has any open connections this command will fail.
I would like to close all existing connections to specific database before running RESTORE DATABASE ... REPLACE command.
I can do closing from Management Studio using checkbox "Close Existing Connection" when deleting database. Actually I need to do the same but from script.
Please advice me how to do it.
Thanks in advance,
Roman
View 3 Replies
View Related
Feb 13, 2008
Hi,
My question is if I close the sqlreader i am using. will that close the connection it uses or the connection will still remain open?
Syed
View 4 Replies
View Related
Apr 23, 2007
I have multiple applications which can potentially update the same trigger simultaneously. Each application:
(1) Reads the contents of the current trigger
(2) Creates a new trigger based on the current contents
(3) Drops the trigger
(4) Creates the new trigger
I need to insure that once one application begins step (1), then no other application can start step (1) until step (4) has completed.
Any ideas on how this can be done? Some databases have a concept of locking tables explicitly, so for them, I can do:
(0) lock table foo;
(1) - (4)
(5) unlock table foo;
Is there such a concept in mysql or is there another way of accomplishing this?
Thanks,
Eric
View 6 Replies
View Related
Nov 1, 2006
I have witten a lot of stored procedures in my project where I did not put dbo before the user tables.My colleague told me that I have to put dbo for all statements other there could be a problem.
Any thought?,
Please assist.
View 6 Replies
View Related
Nov 26, 2007
Hi,
I’m having a situation where I have configured replication between remote sites and my head office, after every 24 hours. It is working perfectly. Now I want to modify it as per new business requirement. For this I need to know the answers to following questions. Any help will be appreciated.
Consider sample database with a master and child tables.
1) It is possible to replicate master table immediately and child table every 24 hour?
2) is there any possibility that we can explicitly replicate a single child record when required? For example, people can see master record without the need to see child table records, but if some one want to see some specific record from child table, can it be done?
Regards,
View 3 Replies
View Related
Sep 23, 2014
I have a Nullable columns. I want the value to be zero if NULL is passed.
1) having a view for every such table,
2) using ISNULL for needed columns in that view
3) using those view for inserts instead of using tables directly.
This way i can reduce the number of places to use ISNULL in all my SPs.I dont want to make it to NOT NULL, as my application impact will be high. And Default constraint does not work here.
View 9 Replies
View Related
Dec 18, 2007
HI all,
I have a windows application which runs a process,
I am updating database column "Status" with Processing when the application is running, and on completion I update it with Staus="Completed" or in case I close the application
I update db with Status="Interupted" .
I have problem that in case while proces is running, power supply or system turns off, the db Status="Processing", but in actual it is interupted.
How will i update?
Please help.
View 1 Replies
View Related
Jul 23, 2005
I have a SQL Server job, which runs mutiple steps. One of the steps(step 3) looks for a record in the database. How can I explicitly failthe SQL server job if the database record does not exist?
View 2 Replies
View Related
May 17, 2005
Hi there,
Here we have got a
asp.net application that was developed when database was
sitting on SQL server 6.5. Now client has moved all of their databases
to SQL server 2000. When the database was on 6.5 the previous
development team has used oledb connections all over. As the databases
have been moved to SQL server 2000 now i am in process of changing the
database connection part. As part of the process i have a login
authorization code.
Private Function Authenticate(ByVal username As String, ByVal password As String, ByRef results As NorisSetupLib.AuthorizationResult) As Boolean
Dim conn As IDbConnection = GetConnection()
Try
Dim cmd As IDbCommand = conn.CreateCommand()
Dim sql As String = "EDSConfirmUpdate" '"EDSConfirmUpdate""PswdConfirmation"
'Dim cmd As SqlCommand = New SqlCommand("sql", conn)
cmd.CommandText = sql
cmd.CommandType = CommandType.StoredProcedure
NorisHelpers.DBHelpers.AddParam(cmd, "@logon", username)
NorisHelpers.DBHelpers.AddParam(cmd, "@password", password)
conn.Open()
'Get string for return values
Dim ReturnValue As String = cmd.ExecuteScalar.ToString
'Split string into array
Dim Values() As String = ReturnValue.Split(";~".ToCharArray)
'If the return code is CONTINUE, all is well. Otherwise, collect the
'reason why the result failed and let the user know
If Values(0) = "CONTINUE" Then
Return True
Else
results.Result = Values(0)
'Make sure there is a message being returned
If Values.Length > 1 Then
results.Message = Values(2)
End If
Return False
End If
Catch ex As Exception
Throw ex
Finally
If (Not conn Is Nothing AndAlso conn.State = ConnectionState.Open) Then
conn.Close()
End If
End Try
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' Getting the Connection from the config file
''' </summary>
''' <returns>A connection object</returns>
''' <remarks>
''' This is the same for all of the data classes.
''' Reads a specific
connection string from the web.config file for the service, creates a
connection object and returns it as an IDbConnection.
''' </remarks>
''' -----------------------------------------------------------------------------
Private Function GetConnection() As IDbConnection
'Dim conn As IDbConnection = New System.Data.OleDb.OleDbConnection
Dim conn As IDbConnection = New System.Data.SqlClient.SqlConnection
conn.ConnectionString = NorisHelpers.DBHelpers.GetConnectionString(NorisHelpers.DBHelpers.COMMON)
Return conn
End Function
in the above GetConnection() method i
have commented out the .net dataprovider for oledb and changed it to
.net dataprovider for SQLconnection. this function works fine. But in
the authenticate method above at the line
Dim ReturnValue As String = cmd.ExecuteScalar.ToString
for some reason its throwing the below error.
Run-time exception thrown : System.Data.SqlClient.SqlException - @password is not a parameter for procedure EDSConfirmUpdate.
If i comment out the
Dim conn As IDbConnection = New System.Data.SqlClient.SqlConnection
and uncomment the .net oledb provider,
Dim conn As IDbConnection = New System.Data.OleDb.OleDbConnection
then it works fine.
I also have changed the webconfig file as below.
<!--<add
key="Common" value='User ID=**secret**;pwd=**secret**;Data
Source="ESMALLDB2K";Initial Catalog=cj_common;Auto
Translate=True;Persist Security Info=False;Provider="SQLOLEDB.1";'
/>-->
<add key="Common" value='User ID=**secret**;pwd=**secret**;Data Source="ESMALLDB2K";Initial Catalog=cj_common;' />
Please help. Thanks in advance.
View 4 Replies
View Related
Jul 17, 2006
Hi, I've created a simple hit counter in my Session_Start event...
Dim myDataSource As New SqlDataSourcemyDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToStringmyDataSource.UpdateCommand = "UPDATE Stats SET Hits = Hits + 1"myDataSource.Update()
It works fine but do I need to close the connection after I've finished with it or is this ok?
Thanks for your help.
View 9 Replies
View Related
May 29, 2007
string ConnectionString = ConfigurationManager.ConnectionStrings["myConnString"].ConnectionString;
SqlConnection connection = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand(@"INSERT INTO CreditAppFile (GI_RB_Div) VALUES(@GI_RB_Div) SELECT @@idientity as 'NewID'", connection);
cmd.Parameters.Add("@ID", SqlDbType.BigInt, 8).Value = NewID.Text;
.
.
Response.Redirect(DisplayPage.aspx?ID=@ID);
i want the ID of the most recently added record to be passed to another page to show all entered data from the prior page... am i close?
View 5 Replies
View Related
Jul 20, 2007
I am trying to select rows from a SQL2000 database table and then write a random number back into each row. I have already looked into do it all in a SP but there are well documented limitations for the SQL RAND function when called in the same batch, so I need to somehow do in .Net what I already have working in classic ASP.
I can't get the UPDATE (part two section) to compile. I don't know how to call the stored procedure inside the 'foreach' loop or extract the SP parameters. I have it working in classic asp but am having a lot of trouble converting to .Net 2.0. Is the below even close to working?
// stored procedure to write externally generated random number value into database
PROCEDURE RandomizeLinks@L_ID int,@L_Rank intASUPDATE Links SET L_Rank = @L_RankWHERE (L_ID = @L_ID)
// Part One select links that need random number inserted.
public DataTable GetRandLinks() { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1A"].ConnectionString); SqlCommand cmd = new SqlCommand("RandomizerSelect001", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSet(); try { da.Fill(ds, "Random001"); return ds.Tables["Random001"]; } catch { throw new ApplicationException("Data error"); } }
// Part Two I need two write a random number back into each row
protected void Button1_Click(object sender, EventArgs e) { GetRandLinks(); int LinkID; // this generates unassigned local variable "LinkID' error int LRank; // this generates unassigned local variable "LRank' error SqlConnection con2 = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1A"].ConnectionString); SqlCommand cmd2 = new SqlCommand("RandomizeLinks", con2); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.AddWithValue("@L_ID", LinkID); cmd2.Parameters.AddWithValue("@L_Rank", LRank); SqlDataAdapter da2 = new SqlDataAdapter();
int RowIncrement; RowIncrement = 0; DataTable dt = GetRandLinks(); foreach (DataRow row in dt.Rows) { System.Random myRandom = new System.Random(); int LinkRank = myRandom.Next(25, 250); LRank = LinkRank; da2.UpdateCommand = cmd2; RowIncrement++; } }
View 4 Replies
View Related
Feb 14, 2008
Hi all,
If this is used eg.
Return selectCommand.ExecuteReader(CommandBehaviour.Default)
Here do i need to close the connection in finally explicitly????
Are there any links which can answer this kind of question ???
Thanks for any help in advance.....
View 3 Replies
View Related
Nov 29, 2005
Hello, I'm trying to run the following snippet as Console app, and I get an error: "a reader is already open for this connection, and should be closed first" I tried to manually say: SqlDataReader.Close() in the begining of the code, but still get the error, Any suggecstions how to manually close the reader? thank you ---------- here's the code -----------using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; namespace ADO.NET { /// <summary> /// Summary description for Class1. /// </summary> class Class1 { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main(string[] args) { SqlConnection cn = new SqlConnection ("SERVER=MyServer; INTEGRATED SECURITY=TRUE;" + "DATABASE=AdventureWorks"); SqlCommand cmd1 = new SqlCommand ("Select * from HumanResources.Department", cn); cmd1.CommandType = CommandType.Text; try { cn.Open(); SqlDataReader rdr = cmd1.ExecuteReader(); while (rdr.Read()) { if (rdr["Name"].ToString() == "Production") { SqlCommand cmd2 = new SqlCommand("SELECT * FROM " + "HumanResources.Employee WHERE DepartmentID = 7", cn); cmd2.CommandType = CommandType.Text; SqlDataReader rdr2 = cmd2.ExecuteReader(); while (rdr2.Read()) { } rdr2.Close(); } } rdr.Close(); } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { cn.Close(); } } } }
View 2 Replies
View Related
Jul 12, 2002
Hi guys.
is there anyway I can find a cursor that is open
so that i can close it?
I have a procedure running daily (across servers). that stopped suddenly with this error.
A cursor with the name 'xyz' already exists.
I tried closing and deallocating on destination server. I am getting the error like "cursor doesnot exist"
I need to run this procedure. i dont want to recycle the destination server.
any ideas?
-MAK
View 4 Replies
View Related
May 28, 2006
How do i close a current connection to a database using t-sql?I fail some time to drop the database getting messages that it'scurrently in use.Using the wizard to delete the database, i could check the option toclose all connections to the db, but how do i do it using t-sql?best regards
View 10 Replies
View Related
Oct 14, 2007
Hello all,
I have a DB on my WM2005 device.
I'm using a program which connect to the DB using a CN.
On the constructor of the DB Class I use the line
static string connString = "Data Source='" + strDB + "'; LCID=1033; Password=" + strPass + "; Encrypt = FALSE;";
SqlCeConnection cn = new SqlCeConnection(connString);
Then I Open the Connection.
Now, in some ways I need to drop a Table.
Before I do so, I disconnect the DB but I'm using only the line
cn.Close();
I saw om the Watch attributes that its not a real disconnect to the DB.
When I try to Drop the Table I get this message:
The system timed out waiting for a lock. [ Session id = 25,Thread id = -2096711882,Process id = -2090594918,Table name = Movies,Conflict type = x lock (s blocks),Resource = DDL ]
And the Table doesn't drop.
Is it related to the constructor line I made?
What is the best solution to Drop a table..and then to get connected again with the DB.
Thanks in advance..
View 5 Replies
View Related
Oct 16, 2007
I am inheriting all my webpages from a BasePage which is storing my sqlconnection to the database. I open the connection in the "protected override void OnInit()" method (is this right?) but I don't know where I should write the close the connection. Can anyone give me any suggestions?
Regards
EO
View 3 Replies
View Related
Apr 19, 2008
How do you close the connection at the SQL Server? I have a backup I want to resotre to SQLExpress using SQL Management Studio Express. When I try, the SQL tells me he can't because the database is in use. I don't realy care about this I still want to restore the database. So I figured it's because there are some active connection to the database. My gues is I have to close those, but how? I also know I can restart SQLExpress and the connection will drop, but this server has more then one database, so I cant always do that. I'm looking for some T-SQL like DROP ALL CONNECTION.
Thanks for the help.
View 5 Replies
View Related
Jul 23, 2005
Hi,since yesterday I have this message everytime I try to open Sql Server"Enterprise manager"; I reinstalled the outfit completely without successany solutionthanksFernand
View 5 Replies
View Related
Jul 20, 2005
HaiIs it possiable to close the current connection screen in the queryanalyser , not to close the query analyser.With ThanksRaghu
View 3 Replies
View Related
Oct 18, 2006
Given that the conversation states are as follows: (Thanks Rushi!)
Event Initiator Endpoint state Target Endpoint state
BEGIN DIALOG SO --
from Initiator
to Target
SEND message(s) CO --
from Initiator
to Target
Target receives a fragment CO SI
of the first message sent
or receives out of order
message
Target received entire CO CO
first message
END conversation at CO DO
target
Initiator receives EndDialog DI DO
message from target
Target receives ACK for the DI CD
EndDialog message sent
END conversation at CD CD
Initiator
When does the 30 minute timer start for clearing the conversation from the sys.conversation_handles table? Is it the same for both sides (initiator and Target) ie, the end conversation at the Initiator. I guess it must be just in case a resend is necessary.
Gary
View 2 Replies
View Related
Nov 5, 2007
is it possible to close automatically report preview after user's print
Noticed there is event print but it fires *before* printers dialog show
I need somethink like AfterPrint
Plz help
View 2 Replies
View Related
Dec 28, 2007
Hi,
This is VERY VERY simple.
Here's a code test I did place in the Form_Load of my C#.NET app.
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "bla bla...";
cnn.Open();
cnn.Close();
cnn.Dispose();
In SQL SERVER PROFILER, the Audit Login takes place as soon as I hit the .Open()
but when I hit the .Close() OR the .Dispose() there's no Audit Logout. The Audit Logout is issued only
when I quit the application.
Is there someone to explain this behaviour ?
Thank you
View 1 Replies
View Related