Ado.net SqlConnection Open Method
Nov 20, 2011I am learning ADO.NET But it very hard for me... I dont understand why have got this compiler error:"Declaration expected" for the connection.Open().[code]
View 1 RepliesI am learning ADO.NET But it very hard for me... I dont understand why have got this compiler error:"Declaration expected" for the connection.Open().[code]
View 1 RepliesFrom my understanding, .Net will pool SqlConnection objects where the Connection String is the same by default. Will the connection still be pooled if I call the Dispose method? This question is asked under the context of an ASP .Net application that at times makes many hits to the database in a single PageLoad event. I want the connections to be pooled, but would like confirmation that Closing and Disposing of the connection once the data operation is complete does not interfere with .Net's handling of the connection pool.
View 3 RepliesIm struggling on how to open an excel workbook without one of two problems.
1. After the first workbook is opened and I close the workbook, if another is opened the worksheet area is "transparent", as in, you can see the desktop or any open app behind excel.
2. Closing excel and opening another workbook after X times (4+?) via the vb.net app I use causes the computer to reboot.
I am stuck thinking it is the method used to open excel within the app.The code below has two methods, both produce the same affect. One method is blocked (makes it easy to test either one).[code]I have two buttons that open workbooks, both have identical code less the workbook requirements.Is there a better or best method to use for opening excel workbooks from vb.net?
[code].....
View 1 RepliesI know that with the Command Button, you can utilize the PerformClick option. I would like to know how you would go about doing something similar for a Combobox.What I am looking to do is open the Combobox within the GotFocus method.
View 2 RepliesI am trying to update some code. I have a vb file that begins with this...
Imports System.Data.SqlClient
Imports System.Data.Sql
Imports System.Data.SqlTypes
[Code].....
...and it accepts it. Why do I need to explicitly write out System.Data.SqlClient every time I use an object from that class???
i would like to know if there's something wrong in this asp.net code:
mydatareader = mycmd.executeReader()
if myDataReader.HasRow then
// Do something
[code].....
I am confused about something and I hope someone here can give me an answer
View 3 RepliesConsider a MyForm class that contains a shadowed implementation of Show(). It also contains a CreateForm() method, which accepts an instance of the form and calls the shadowed sub:
[Code]....
What would happen if you call Close() on a SqlConnection object before you call Close() on a SqlDataReader using that connection?
Actually, what I really want to know is whether or not the order in which you Close them matters. Does calling SqlConnection.Close() completely close the connection, or will it remain open if you do not call Close() on a SqlDataReader using that connection?
I don't think I really understand how connection closing works.
I keep getting the following exception when I do:
[code]...
I'm having a problem with my global connection function. It used to be a readonly property but I changed it to a function because the code anaylsis engine was complaining about my property raising exceptions. The function is designed to take account of our offsite database mirroring system, so if it can't create a connection to the principal server it switches the connection string to the mirror server. This works fine in another project we have:
Public Shared Function Connection() As SqlConnection
If String.IsNullOrEmpty(ActiveConnectionString) = True Then
Throw New PropertyNotSetException("Cannot call Connection() before
[Code].....
I have a SqlConnection global variable in my proyect that it is always open (I wouldn't like to start a discussion about keep the connection open all the time or close it everytime a transaccion is executed).
This variable is sent to every class I need to execute a function or method. Instead of checking the connection in every single operation, is there any way to monitor the connection state in a centralized way ?
I'm trying to add transaction support to our database object.This object is a Remoting object. (this to ensure that on the Windows Client, no database connection is required.)Now I want to add support for transactions;Basically, a client will need to use it like this;
BeginTransaction
ExecuteNonQuery("insert...")
ExecuteNonQuery("insert...")
[code].....
I am recently new to Visual Basic and am starting to learn some things i have managed to connect to the SQL Server and Insert rows to a table. But is there a way to be able to re-use an already existing connection ?My code below. I tried to create a class for the Connection object.
Imports System.Data.SqlClient
Imports System.Data.Sql
Public Class dbConnection
[code]....
[code]in this code, do the objects con and cmd get disposed because the return statement is placed before the end using statement.
View 1 RepliesImports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Configuration
Module Module1
[code].....
this is my connection string on my pc how can i make this as a dynamic connectionstring so i cant remove the db and get a new connectionstring?
I asked a question earlier where I was told a simple way to "bind data to objects" is to just run a SqlConnection(connectionString). The response also included a comment saying I could get fancy with L2S and Entity Frameworks, so I looked deeper into those. It seems all you have to do with the DataContext object is point to the database. Why would SqlConnection be a benefit? What is the difference (or pros/cons) of using either one of these? Is one more "standard"? Is one more modern?
View 1 RepliesI'm running a multithreaded application that connects to a database, the connections are closed when I'm done with them (and I dispose of all the threads). I've tried clearing the connection pools, setting pooling=false and I've used both .dispose and .close.
I get the error "cannot drop the database X because it is currently in use" if I try to drop the database I connected to after the connections have all been closed.
Below is my code:
Dim comExecuteInsert As New SqlCommand
Dim comm As New SqlConnection
If (Not comm Is Nothing) Then
comm = Nothing
End If
[Code] .....
The stored procedure creates temporary tables which it later drops and inserts data into tables existing in the database.
HTML SqlConnection connection = Getconnection() Anybody knows which reference should be added for Getconnection()? I am using 2008. Tried System.Data but...
View 4 RepliesThis seems to be a great article by Scott Mitchell for creating syndicated feeds in ASP.NET 3.5. The problem for me is that it uses C# and Linq, which I'm not as sharp on at the current time.[URL]...Does anyone know where an example might exist for the System.ServiceModel.Syndication namespace that can produce a syndicated feed like this article using VB.NET and a SQLConnection object?
I've looked around and every example seems to be produced in C# and Linq (which is probably a testament to my need to learn them soon rather than later).
My code read a thousand files, and for each file a connection is made and open to check against a recordset in SQL. After 143 files, the application will stopped and thrown this exception regarding maximum pool size reached. What I don't understand is I'm closing the connection after every file is processed, could it be I'm doing it incorrectly?
Please see my code below. I was only able to make this work by setting max pool size = 3000 in the connection string, since closing the connection does not seem to work.[code...]
I have seen some comments about the difference of sqlconnection vs oledbconnection.
View 9 RepliesI have an asp.net web app. It has a shared class, and I want to have the connection string the same through out the site. My string is in my web config, but I don't want to type this all over the place:
View 3 RepliesI am preparing to deploy a web service that uses SqlConnection primarily as its means to get to the database, and I am adding some new methods that use a DataContext instead of thatand the default constructor and DBML file would use a connection string refering to my development machine (I believe...)
View 1 Repliesi want to know how to download sqlconnection data component, which site i can download....
View 3 RepliesI have imports namespace System.Data.SqlClient.I just create object of SqlConnection,But error is there-
'SqlConnection' is ambiguous in the namespace 'System.Data.SqlClient'.
[Code]...
I have a VB.net 2005 application that will use both Access and SQL server databases. I have DSN namesfor both access and sql server database. I used OleDb.OleDbConnection to open the Access database and it works fine. I am trying to make it work with sql server database. Do I have to have to have separate source codes using Sqlclient.SqlConnection and its related name spaces? Can I use odbc.OdbcConnection name space
View 4 RepliesIt's possible to select random a column in SQL 2005 using SqlConnection? And this column to send "UserID" e " ChName" for Label1.Text and Label2.Text?
example: after choosing random the column, send "UserID" and "ChName" to Label1.Text and Label2.Text.
I am creating class libraries in my project so that I can update code without having to update the whole app.I created a class library project and added some code to it. I also added a reference to System.Data.SqlClient and also imported it into the class file.I am getting an error and I have never seen it before. Been looking online and not able to find an answer yet.
View 2 Replies