Performance Problems When Using Multiple SqlConnection Objects?
Feb 9, 2007
Hello,
I am planning to use three databases on the local SQL Server. DB1 will be for App1, DB2 for App2, and DB3 will hold tables, that both, App1 and App2 need to access.
Obviously, I need in App1 and App2 at least two SqlConnection and SqlCommand objects, one that access their respective databases, and one that will access DB3.
Will this result in a worse performance? (The using of two SqlConnection objects in one aspx page as example, and switching them)
Should I for better performance get rid of DB3 and add the tables there to DB1 and DB2 ? (Thus multiplying data, but, if the performance will be much better, it will be fine with me)
I have a sql server project where I have added 1 stored procedure (named StoredProcedure1) and 1 class (named MyClass). MyClass has two functions Func1() and Func2(). The stored procedure simply instantiates MyClass and calls Func1().
Func1() creates a SqlConnection object using "context connection=true" - opens the connection and then calls Func2(). Func2() also creates a SqlConnection object using "context connection=true" - and attempts to open the connection. However when attempting to the Open() call inside Func2(), the code just exits. What gives? The code is pasted below, thanks!
*******THE STORED PROCEDURE************** using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using SqlServerProject1;
public partial class StoredProcedures { [Microsoft.SqlServer.Server.SqlProcedure] public static void StoredProcedure1() { // Put your code here MyClass obj = new MyClass(); obj.Func1(); obj = null; } };
*******THE CLASS "MYCLASS"************** using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server;
public class MyClass { public MyClass() {
}
public void Func1() { using ( SqlConnection conn = new SqlConnection("context connection=true") ) { conn.Open();
Func2(); conn.Close(); } }
public void Func2() { using ( SqlConnection conn = new SqlConnection("context connection=true") ) { if ( conn.State != ConnectionState.Open ) conn.Open();
if ( conn.State == ConnectionState.Open ) conn.Close(); } } }
Hello All, I am new to data access and i have got the problem to display the data into the page by binding the gridview with sqlConnection, sqlCommand and sqlDataReader objects. The actually code is written as:protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) {SqlConnection myConnection; SqlCommand myCommand;SqlDataReader myReader; myConnection = new SqlConnection();myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["LatteConnectionString"].ConnectionString; myCommand = new SqlCommand();myCommand.CommandText = "select * from AntiVirusVendors";myCommand.CommandType = CommandType.Text; myCommand.Connection = myConnection; myCommand.Connection.Open();myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection); GridView1.DataSource = myReader; GridView1.DataBind(); myCommand.Dispose(); myConnection.Dispose(); }
}
and the GridView in html is listed as: <div> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </div> So the problem is ---> there is nothing shown in the page, no errors no anything.... just the empty page. Any ideas would be appreciated. Thanks in advance! Joe
Im just curious, can anyone explain what exactly the methods do within the objects (sqlconnection, sqlCommand, SqlDataReader) . and why it takes three objects to carry out a connection. Php only used one object I believe.
But most of all i would like to know how they work. like sqlCommand carrys the connection (sqlcommand.connection) while sql connection retrieves the address connection (sqlconnection(connectionstring)). what does Sqlconnection do once it gets this address. and what does it give sqlcommand when its ready to take out the query and put it in the reader once the sqlconnection.open() to make it simple. let me put it this way sqlConnection con = new SqlConnection(_connectionstring); // server address comes through here. along with security and database name what exactly does the object con do ? it runs through the constructor and does what ? SqlCommand cmd = new SqlCommand(); cmd.Connection = con; //So now what ever the SqlConnection did with the _connectionstring. it now passes it through the connection property. the connection property does something with value of con. what is it ?? cmd.CommandText = 'select, ID, Name, Price.....' // I think i know what that does con.Open() // I know that the connection opens here. but what exactly does this method do to make it open ???????? sqlDataReader reader = cmd.ExecuteReader(); im some what confused with this one. sqldataReader reader was never declared and its not even a static method. What exactly is it ????? cmd.ExecuteReader() now takes the property connection which did something with the con value. then it used the commandtext property to request the query. it takes con.open does something and now its execute reader. Im a lil confused last but not least, con.close() what does that do ?? its alot but can anyone fill me in. or should i say fill(me); in lol, get it. never mind.
Hi there, I'm not sure if the way I handle SqlConnection in my apps is the most performant one.So my apps use db heavily and there are loads of classes with methods like 1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString)) 2 3 {conn.Open(); 4 // more code here 5 } 6 7 As I use using the connection is closed and the object is disposed when leaving the code block.I know that the connection is taken from a pool and when closed it returns to the pool as though I'm not sure if it is better to have one "global" SqlConnection objectand to use that object for all classes or most of them. What about the ConfigurationManager, doesn't it slow down the performance as well when I'm accessing the ConnectionString value thousands of times?I hope someone can point out the issues.Many thanks in advance, Limbic
anyone else having issues with the SQL Server 7.0 specific objects in performance monitor not being available from remote locations. I am monitoring our production SQL Server 7.0 machine from my local, development SQL Server 7.0 box. If I try to access the SQL Server objects for the development server (local) I have no problem. If I try to access the production machine's (remote) objects, they are not available in the object drop down. I'm also able to access the development objects from my workstation (third machine) but not production.
Any tips would be greatly appreciated...I would really love to be able to see how well (or not so well) the databases are performing in real time.
Is there a way to delete from multiple tables/views a column with a specificname? For example, a database has 50 tables and 25 views all have a columnnamed ColumnA. Is it possible to write a simple script that will deleteevery column named ColumnA from the database?Seems to be it would be possible and I can somewhat vision it usingsysobjects but without wanting to spend too much time generating the script(when I could in shorter time manually delete) thought I'd pose the question.Thanks.
I started out with trying to get to know the existing SQL Servers (6.5 and 7.0). I am missing some Performance Monitor objects (ie SQL Server: Buffer Manager, SQL Server: General Statistics, etc). I am surprised that it is missing.
A typical SQL Server setup: * NT 4 with SP6 * SQL Server 7 (standard) with SP2 * 2gig Mem * Over 50gig HD
Does any of you ever have this problem? Any solutions? Any answer would be greatly appreciated.
Have a sql 2000 db which I have no say in design, just make it run. My typical sql counters such as system queue, and buffer cache and cache hit ratio are all good. If I need to monitor disk activity (mainly how fast my data is being read, how long the user is waiting for that data for both reads and inserts), what are the best counters for this, and what value should throw up a red flag.
I want to delete a user on local but in order to do that I apparently need to delete the schema. The schema has many objects in it. Can I and what is the syntax to move multiple objects from let's say XXX to dbo so I can delete the schema XXX
We are trying to create some alerts in our SQL Server 2014 BI edition.Issue is that, after I chose "Type" as "SQL Server performance condition alert" nothing is listed in the "Object" list box.SQL Server event alerts are working. Issue is only with "SQL Server performance condition alert".
please help newbieI need to create a lot of objects the same type (let's say: schemas)I wish to use paramerized block in loop to do so.- how to put names of my objects to such control-flow?belss you for help
I have a legacy prod db of 102Gb which contains 101Gb of free space. The db comprises 2 Primary (.mdf's) on one drive and over 200 (.ndf's) residing on one logical drive, (4 physical drives with RAID 5). ie. Each user table object has its own (.ndf). Some of these tables have been allocated up to 15Gb.
Limited documentation suggests that performance benefits can be achieved by allocating a maximum size to certain key tables rather than setting the table properties to autogrow.
No mention is made of grouping these files into filegroups to potentially achieve the same performance gains.
Transportability of this db is now a problem since no other test/dev/prod boxes contain enough free space.
I propose to re-create the db and have the user data tables reside within the (.mdf) - possibly even group highly active tables within filegroups.
Are there any benchmark tests or KB articles to indicate/support the original strategy of using multiple (.ndf's) over data tables within one (.mdf)??
I'm having serious problems with the IDE for SSIS for projects that contain more than 5 packages. Especially if these packages call each other with a run package task thats configured with a file connection. Especially annoying are the 20+ "Document contains one or more extremely long lines of text.." messages that pop up during loading / validating. For my project with around 30 packages it takes me around 10 minutes to click through all these pop ups in addition to the long loading time.
Anyone got any tips on this specifically or how to improve performance in the IDE in general? As it is now, the product is a REAL pain to work with for large projects.
passing serialised objects to a stored procedure for the purpose of data inserts. I see this as being a way to handle multiple row inserts efficiently.
However, in my limited use of XML data I am not so sure how to link the data when I have a dependency on another "object" within the serialised XML.
Below is a code snippet showing what I have so far.
The first insert statement works fine - but how to retrieve the identifier created by the DB - I want to use an SQL statement that finds the record in the table based on the XML representation (of the PluginInfo), allowing me to insert the ConfigurationInfo with the correct reference to the PluginInfo
DECLARE @Config NVARCHAR(MAX) DECLARE @Handle AS INT DECLARE @TransactionCount AS INT SELECT @Config = ' <ConfigurationDirectory > <ConfigurationInfo groupKey="Notifications" sectionKey="App.Customization.PluginInfo"
I apologize since this seems to be a fundamental question, but I did try to search and there seems to be something wrong - after clicking on the "search" button, the page just will not update... I even tried "advanced search" but no luck there, either.
Anyway, my question is about writing multiple data rows to tables in a SQL Server database. Currently I'm using embedded SQL from a VC++ 2005 .Net program to write data to a SQL 2005 Express server (either on the same PC or on another, via TCP). As data becomes available, I issue INSERT statements, one by one. One row is about a dozen columns, typically 8 bytes each, for each of the few tables in the database. In most cases, I have several rows of data available at the same time. Those rows come at the rate of around 200-1000 per second for the different tables. With that setup, my SQL server is not able to keep up - the data ends up getting buffered in the program, waiting for the server, the server process uses just about all the CPU cycles it can get, etc.
I'm reading the "SQL in a nutshell" book from O'Reilly but it's mostly language oriented, it doesn't say much about performance improvements. It would seem natural that one could improve the performance. For example, when I do a SELECT query, the data comes very quickly, which makes me think that it is the overhead of making those individual calls with small amount of data. I would think that I should be able to request that multiple rows are written at the same time with a single SQL statement, and that this would improve the performance. However, I have no idea how to do that.
I did try one thing - enlisting the sequence of INSERTs into a single transaction, thinking it will all get buffered and only get written to the server after the Commit command is issued. I did that but it doesn't seem to help. What should I try to alleviate this problem? One thing to consider: although I use SQL Server for testing, I am trying to keep compatibility with other databases, e.g., ODBC to any available data source, including MS Access over Jet. I would love it if the solution to this were compatible (i.e., not involve any Transact SQL or other vendor-specific tricks). I thank you in advance for your assistance!
I wonder if anyone has any hard fact based pro or contra, especially onperformance, about having views as opposed to tables when the object isbeing accessed for read only by multiple sessions/users/spids. I amparticularly concerned about the multiple instantiations of the view.Relevant thoughts on this are much appreciated.Thanks,Caveman
Hi all, In my project, I have a website and through that, I run my reports. But the reports take a lot of time to render. When I checked the profiler, it showed that the SP for the report is run around 4-5 times. Due to this, the report rendering takes a lot of time.
When, I ran the SP with the same set of Parameters in Query Analyser, it ran in around 18 seconds. But when I ran the report from web interface, it took around 3 minutes to completely show the data. And the SP has been run 5 times.
I am having serious problems with Report's performance because of this. Many a times, report just times out. I have set the timeout as 10 minutes. And because the Sp is run 5 times, the report times out, if there is huge amount of data.
Is it possible to create a cluster configuration, where 2 (or more) SQL Server instances running on different servers will simultaneously serve the same database attached to the same storage? Something like this:
Instance A Instance B Instance C (active) (active) (active) | / | / | / SAN for Database and Quorum
The point would be to improve reliability and performance at the same time. All nodes would share load. If a node fails, the other nodes still work and take over the load.
I know a failover cluster can be done, where 1 instance is active and others are passive (active/passive) which improves reliability, but in this configuration just 1 instance is serving at the same time.
(As far as I understand, the active/active configuration is meant to run different databases on 2 (or more) instances such that the databases on a failing node are taken over by any other instances in the cluster.)
we are using SSRS 2012.Oracle 9i as back end database. Select A,B,C from view where A in (Param1) in above query when I am passing 1 value getting output in 30 sec. when I passed two values getting time out error in SSRS. how to pass multiple values in Oracle 9i in SSRS report.
I have a problem where my users complain that a select statement takes too long, at 90 seconds, to read 120 records out of a database. The select statement reads from 9 tables three of which contain 1000000 records, the others contain between 100 and 250000 records. I have checked that each column in the joins are indexed - they are (but some of them are clustered indexes, not unclustered). I have run the SQL Profiler trace from the run of the query through the "Database Engine Tuning Advisor". That just suggested two statistics items which I added (no benefit) and two indexes for tables that are not involved at all in the query (I didn't add these). I also ran the query through the Query window in SSMS with "Include Actual Execution Plan" enabled. This showed that all the execution time was being taken up by searches of the clustered indexes. I have tried running the select with just three tables involved, and it completes fast. I added a fourth and it took 7 seconds. However there was no WHERE clause for the fourth table, so I got a cartesian product which might have explained the problem. So my question is: Is it normal for such a type of read query to take 90 seconds to complete? Is there anything I could do to speed it up. Any other thoughts? Thanks
Public Conn As New SqlConnection("Data Source=localhost;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")Public Conn As New SqlConnection("Data Source=XX.XXX.XX.XXX;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX") This two commands are in my application. I switch between the two so I can test my application. When I put my application on the server, I use the localhost SQLCONNECTION. The other is commented out. However, the application continues to connect to the server with the address that is commented out. THIS IS VERY FRUSTRATING... HELP!!!!
Hi, Someone can explain to me what happend in this situation...i have this and want to call a procedure with connection parameters protected void Button1_Click(object sender, EventArgs e) {
SqlConnection edo = new SqlConnection(); edo.ConnectionString = "server=myserver; uid=admin; pwd=; " + "database=name1"; SqlCommand com = edo.CreateCommand(); com.CommandType = CommandType.Text; My_proc(edo, com); } protected void My_proc(SqlConnection edo , SqlCommand com) { try {edo.Open(); } catch{} finally{ edo.close();} }
Well what happend with the SqlCommand and SqlConnection when return to Button_Click() Are they alive? Can be used in Buton_Click like parameters for another procedure? or i have to create it again?Thx in advance..
please help me !!!?I have a problem with sqlconnection definition when I add the sqlconnection from toolbox :like this: Imports System.Data.SqlClientPartial Class _Default Inherits System.Web.UI.Page Private Sub InitializeComponent() Me.sqlConnection1 = New System.Data.SqlClient.SqlConnection Me.sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa" Me.sqlConnection1.FireInfoMessageEventOnUserErrors = False End Sub Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim cmduniversity As SqlCommand Dim dtruniversity As SqlDataReader cmduniversity = New SqlCommand("select * from university", sqlConnection1) sqlConnection1.Open() dtruniversity = cmduniversity.ExecuteReader dtruniversity.Close() sqlConnection1.Close() End If End SubEnd Classin the sqlconnection.open the nullrefrence exception occures butwhen i define myself this exception dosn't occure.like this: Imports System.Data.SqlClientPartial Class _Default Inherits System.Web.UI.Page Private Sub InitializeComponent() End Sub Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then sqlConnection1 = New SqlConnection sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa" sqlConnection1.FireInfoMessageEventOnUserErrors = False Dim cmduniversity As SqlCommand Dim dtruniversity As SqlDataReader cmduniversity = New SqlCommand("select * from university", sqlConnection1) sqlConnection1.Open() dtruniversity = cmduniversity.ExecuteReader dtruniversity.Close() sqlConnection1.Close() End If End Subwhere is the problem?
Can someone help me out? I am trying to establish a SQL server connection in my C# code. My C# code crasheds though. Can someone tell me what Iam doing wrong? Here is the C# code:
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["TheDividerConnectionString"]); Here is the connection string as defined in the web.config file: <connectionStrings> <add name="TheDividerConnectionString" connectionString="Data Source=BVCOMPUTERSQLEXPRESS;Initial Catalog=TheDivider;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
Would anyone ahve any ideas why when i debug this code, it stops and freezes at cn.open(); A raw sql query against the DB works in this format. int top=10;SqlConnection cn = new SqlConnection("Data Source=blah;Initial Catalog=blah;Integrated Security=blah"); SqlCommand cmd = new SqlCommand("SELECT DISTINCT TOP (@nrows) [CustNu] FROM [Customer] WHERE [CustNu] like @term", cn);cmd.Parameters.AddWithValue("nrows", top);cmd.Parameters.AddWithValue("term", prefixText + "%");
List <string> suggestions = new List<string>(); cn.Open();
HiI would like to have some help for my problem.I'm trying to retreive the connectionString "MyConnectionString" from app.config using method 1 or 2 to get a connection to my DB (without any success.) --> Partial codepublic SqlConnection GetConnection() { // reference to System.Configuration Library is done 1 SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);--> thrown NullReferenceException on Conn.Open(); 2 SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["MyConnectionString"]);--> thrown InvalidOperationException ConnectionString not initialised return Connection; } public Contest GetContestFromDB() { SqlConnection Conn = GetConnection(); Conn.Open(); ->> thrown Exception 1 or 2...Here my app.config :<?xml version="1.0" encoding="utf-8"?><configuration> <appSettings> <clear/> <add key="MyConnectionString" value="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMesdocumentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add> </appSettings> <connectionStrings> <clear/> --> using <clear/> to avoid to load from machine.config <add name="MyConnectionString" connectionString="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMes documentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add> </connectionStrings></configuration> I'm using Visual Studio 2008 with SQLServer 2005 Express Embedded and WindowsXP SP2 .Have you got any idea ?I'm not able to sleep anymore...And I've test this code in ASP.net with the same ConnectionString in the web.config file and it works !!I'm lost.By the way, thx if ou get an answer ww4ss