SqlConnection And Sql Express?
Jul 20, 2011I am confused about something and I hope someone here can give me an answer
View 3 RepliesI am confused about something and I hope someone here can give me an answer
View 3 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 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 RepliesWhat 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]...
From 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 RepliesI 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 RepliesI am working on uses the ThreadPool class and specifically the QueueUserWorkItem method to launch its background tasks. I am however having an issue related to SqlConnection timeouts. My error is this: "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."
This code is using all available ThreadPool threads because it is processing nearly 100,000 items, each on a threadpool thread, and updating an SQL database. So my question is this? Has anyone ran into a similar problem or could shed some light on a resolution to this issue? In testing, if I use the threadpool. setmaxthreads function and give it a value of 100 (to match the default Sql connection pooling count) then all runs just fine, but much to slow to process this much data.
[Code]
Is there something wrong with my connection string that I would get this exception thrown back at me from my code? I have the string saved in the code and when I try to create an SqlConnection I get the exception above thrown and below is my connection string which is actually the address to my DB file.
Connection = "Data Source=.SQLEXPRESS;AttachDbFilename= C:Documents and SettingsTTTMy DocumentsBASEO.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
I'm just using the default SQL Server Express in my vb 2008 express edition as my database server for my database operation. When I tried to update the records on my table I got a runtime error which indicates the error on this line 'myCommand.ExecuteNonQuery()'and it highlights a yellow background on it. The runtime error says "SqlException was unhandled: An expression of non-boolean type specified in a context where a condition is expected, near 'Number'. ".
Imports System.Data.SqlClient
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim myConnection As New SqlConnection
Dim myCommand As New SqlCommand
[code]....
I tried to start using VB 2010 Express with a program I originally developed with VB 2005 Express that I moved to VB 2008 Express successfully a couple years ago. It uses a database file (*.mdf) that is on the computer ( not out on a server). When attempt to run the program in debug mode, I get the following error "An attempt to attach an auto-named database for file C:Documents and SettingsTomMy DocumentsQuizzing StuffQuestion Database 2010QuizQuest ionGameQuizQuestionGameinReleaseQuizQuestionDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
I first made a copy of the entire project folder that was working in VB 2008 Express and gave it a different name. In VB2010 I opened the project in the copied folder and it said it successfully converted the project. I am able to open the Data Source inthe Designer and see the database structure as I expect. I think the project is still using SQL Server 2005 Express (because it is what is checked in the list of prerequisites on the Publish tab).
Note, I have programmed off and on for many years, but fairly new to using databases and SQL Server.