.net - CommandBehavior.SingleRow Causing DB Connection To Remain Open?
May 21, 2009
Recently I was working on a project in VB.NET, and I was encountering a mysterious problem with some of the DB connections. This was a project that I inherited from someone else and they had used something like this:
Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection And CommandBehavior.SingleRow)
//after reading data
reader.Close()
It appears as though this was causing the connection to not close properly all the time. I've removed the CommandBehavior.SingleRow, and it seems to be working ok now, but I was wondering if anyone else has encountered this? Does anyone know why that would not work? I've seen CommandBehaviors combined in this way before, but it has never caused that problem before.
I have mdi application, on main form which is mdi container and has a tree view. i open the child form on afterselect even of treeview. the issue i'm facing that i open the form but focus remain on tree view until i click on the the form. my question is how i can give focus to form rather it stays on treeview. i tried frm.focus also activatemdichild(frm) no sucess.
My application requires a user to log in and allows them to edit a list of things. However, it seems that if the same user always logs in and out and edits the list, this user will run into a "System.Data.SqlClient.SqlException: Timeout expired." error. I've read a comment about it possibly caused by uncommitted transactions. And I do have one going in the application.
I am getting an ArgumentOutOfRangeException when I try to run the following code,[code]the table that is being read has a single row of data, the database and connection are fine as I can run INSERT/UPDATES etc but wherever I have used a datareader I am getting this exception each time on the "Using reader As MySqlDataReader" line.
i make a class and when i call on form then that error occurs "ExecuteNonQuery requires an open and available connection, the connection Current stat is close "
Class Code isImports System.Data.SqlClientImports System.DataImports System.StringPublic Class DatabaseKits Dim Cn As New SqlClient.SqlConnection Public Function BuildConnection() As Boolean Try Cn.ConnectionString = "Persist Security Info=False;Integrated Security=True;Trusted_Connection=Yes;database=BizAimsPro2008;server=Server-2k3s" BuildConnection =
I'm developing a device app in VB.net that will access a SQL Server database. I need to establish a connection when the app is launched, and keep the connection open until the app is closed. I've done the following:In the Master Module:
Public CNN As SqlConnection
In the Main menu form load:
CNN = New SqlConnection(sqlConnString) CNN.Open()
Then when I want to read from the database:
Dim sqlDR As SqlDataReader SQL = "SELECT Name FROM Table"
[code]....
When I run the same code without the global CNN, but rather dim the connection inside the Select function, all works well.
I'm trying to insert a new records into database, one of those records is a "datetime"...when I type a wrong date, and try to insert those values into database, i get an error (about wrong typed date etc.)...ok, that's fine, things need to work that way. But here comes the problem, I correct the date, and then try to insert values again...here I get an error from the post title. And this doesn't work until I close that form and run it again...here's part of my code:
Dim cvLicence As New SQL Try cvLicence.upis("INSERT INTO blabla (itsnotimportant) VALUES ('something')") MsgBox("everything's fine", MsgBoxStyle.Information)
In my program, I have a timer with a inteval set to 1000ms. The timer is executing a MySQL-command, and right now I'm opening and closing the connection each time.
I have a .mdf file that I open through an Open Dialog Box and use in a ConnectionStringBuilder (where I have the user instance set to True). Later, in one of my button clicks, I try to open the connection (connection.Open()). It then gives me an error as follows: "Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances."
Here is my code:
Option Strict On Imports System.Data.SqlClient Public Class frmMain
I am creating a login form together with sql as may databse but when i run may program an error occur at "myData = myCommand.ExecuteReader()" stating that "Connection must be valid and open" what should i do on that to make it fix? [code]
I am currently working on a login page using vb.net. I would like to know how to make connection to an access database and verify that the user logged in is a valid user
I'm trying to connect to a database and keep the connection open for any amount of user activity/queries within the database. Currently I have a connection that opens and closes for any query (save, update, etc...) which requires the logon process to the back-end every time the user saves etc... Is there a way to simply connect and leave the connection open so there won't be a lag time when running the query due to the logon process? This is what I'm using:
In our application we use IDataReader which actually call function from one.dll where weExecureDataReader() We have many calls in application and in some places For some reason I am getting error message "DataReader already open" but I am not sure where.What will happend if I simple close that conection in the that .dll? Am I going to make trouble to database because one datareader left opened? I assume closing connection will close reader too and gargage collector will manage that left opened datareader..
SQL connections confuse me sometimes In almost every SQL related code on the internet the routine is like this;
* Open connection * Execute SQL command * Close connection
Is it good practice to just open a connection when the application starts and use that connection until the application closes?I know that sequential connections are required when processing more queries, but what if I need to poll a certain Table every x seconds? Isn't is better to keep that single connection open for as long as the application is running (and re-open when a failure occurs) instead of opening a new connection every x seconds?
I'm trying to insert data into a mysql database, I'm using xampp as well if thats of any relevance? I keep getting this error: Connection must be valid and open.
on cmd.ExecuteNonQuery()
I'm following my Microsoft Access application that I've also written as a reference and that works perfectly.' This is the code for inserting into an access database which works and is tryed and tested:
Imports System.Data.OleDb Public Class frmEnterDetails 'text box variables
I am developing an application that is using a Jet database (Access 2007). The database is local to the project (e.g., on the same drive and in the project directory). Any time I attempt to access the database (to create another DataSet, etc., via designer, etc.), I get the ubiquitous "Failed to open a connection to the database" with: No error message available, result code: E_UNEXPECTED(0x8000FFFF). Opening the Database Explorer and attempting to attach to the database results in the above as well. There are no apparent locks on the file, etc., and I'm the sole developer for this.
In the first form I will load Tabels in the secound I want to open the DB Connection. I wrote a Class which enables me to open and close the connection
I'm trying to a open a connection to a local database and no matter what I try it just won't work (I'm pretty new to SQL Server and VB for that matter) I tried using 'sqlconnection' with different connection strings but none of them worked or gave me any useful error messages so I tried using 'OleDBConnection' instead, this hasn't worked either and it gives me this error instead:"A first chance exception of type 'System.NullReferenceException' occurred in MyProgram.exe"
Here is the code I am currently trying:
Private Sub MemDetailsSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ConnectionString = ("Provider = Microsoft.Jet.OLEDB.4.0;" & "Data Source = Database.sdf") DataConnect = New OleDbConnection(ConnectionString)
Is there one out there? I try to include this and it says something about the Oracle connection not being compatible with the target framework. Any ideas? Or how can I change the target framework of the project without breaking the visual studio power packs?
this is general to any operation calling an SQL server, or anything requiring an open connection at that.
Say I have anywhere from 20 to 1000 Select calls to make for each item in data being looped. For each step, I'll select from sql, store data locally in a struct, then proceed. This is not a very expensive call, so should I keep the connection open for the entire loop? Or should I open and close every step?
How expensive in run time is opening a connection? I would think it'd be better to keep the connection open, but would like to get the correct response for this.
I installed SQLExpress 2008 on my computer this afternoon and have been trying to create a new database and open a connection to it. I found this code online and tried it:
Dim conStr As String = "Server=MSSMLBIZ;Database=;Trusted_Connection = yes"