|
Easy one... Open and close it each time. Don't keep an unused connection open, it's just a waste of resources. Once a connection has been made, it will get put in the pool anyway (providing you have connection pooling on) so the next time it connects it won't take as long.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks for the response.
Just a quick one though.... Even if you have to insert X amount of records every couple of seconds / minutes?
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Well it depends... if you don't know how long between inserts then yes still open close each time, actually even if you know it will be every second on the dot I would still go for Open/Close each time. The only time I would keep it open is if I was going to do all the inserts at the same time with no other stuff being done in between.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks for the info.
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
This thread confused me a little. Is it better to open and close a connection for each query even in a short ASP.Net page?
I've always thought that
<%
cntDB.Open()
MakeAQuery()
'Do something else
MakeAnotherQuery()
cntDB.Close()
%>
Was better than
<%
cntDB.Open()
MakeAQuery()
cntDB.Close()
'Do something else
cntDB.Open()
MakeAnotherQuery()
cntDB.Close()
%>
Maybe simply I misunderstand something.
|
|
|
|
|
Well it depends what your 'Do Something Else' actually does.
If it's simply setting the text of a textbox of something similar then it would probably be best to do your first suggestion and keep the connection open (thou I doubt you would see a difference in performance if you have connection pooling on). If your 'Do something else could take some time then yes re-opening the connection is slightly costly but its better then wasting resources keeping the connection open.
Basically it depends what you do in between the database queries but I would generally close mine each time. Especially if I was using a custom class that handles my database work for me and should naturally close a connection after it finishes as It will not know if to expect another one any time soon.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Well, basically my pages make some query and print out the result. Anyway I've found a serious problem, i have to use the MySql ODBC driver 3.51 which doesn't support connection pooling!
It's a verified bug! http://bugs.mysql.com/bug.php?id=12552
One day I'll pass to the native connector (but i'll have to replace tons of OdbcConnection, OdbcCommand, etc. with the respective MySql* names)
I think the better solution is makeing as less connections as possible and maybe set a short timeout for connections (now it's 60 secs and infact, through SHOW PROCESSLIST, i can see several threads sleep for 60 secs and then disappear).
Thanks!
|
|
|
|
|
That code you linked to is some of the worse ive seen. Its awful, don't use it.
|
|
|
|
|
Thanks for the head sup.
Any example code or wrapper that you have or might know of that is considered to be good?
Thanks in advance
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Personally I like the Microsoft Enterprise Library for data access, but in all honesty I usually roll out my own wrapper for this purpose.
The important thing to note about the library you linked to is that they are trying (for some odd reason) to circumvent the connection pooling that is already present in ADO.NET, as well as using dynamic sql for data access which is inherantly slow and unsafe.
|
|
|
|
|
|
At least it was formatted pretty!
|
|
|
|
|
Hi to all
My need is to create a Dashboard using C#. Currently I am using Framework 2.0.
I want to know that is there any class of library by using that I could make
my Dashbord quickly.
I am also new to .NET and in the beginning state. So Please gimme an idea How can
I complete the task with .NET using some tools present in .NET.
I have heard that there is some updates regarding Dashboard in .NET framework 3.5 service pack 1.
Is it true.
Will it solve my problem ?
I don't want to use some readymade tools from some other providers.
Please advice me as soon as possible.
Thanks in Advance
Amit
|
|
|
|
|
Here's one solution, as you are new, why don't you try learning the basics and then work your way up until you have a better idea about how you could achieve what you need. Then give it another go...
Or is this URGENT, what do you have to do it for?
Life goes very fast. Tomorrow, today is already yesterday.
modified on Thursday, May 21, 2009 5:27 AM
|
|
|
|
|
ammit.it2006 wrote: create a Dashboard using C#.
What exactly do you mean by 'a dashboard'?
ammit.it2006 wrote: How can
I complete the task
By writing code and designing a UI.
ammit.it2006 wrote: I have heard that there is some updates regarding Dashboard in .NET framework 3.5
If you haven't yet written it and sold it to Microsoft then I don't see how there can be updates for it in the 3.5 framework version. I think you're probably refering to WPF for fancy UI stuff. If so then yeah that's in there.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
DashBorad gives the view of present position of the company , using Pie charts and table charts etc.
http://www.microsoft.com/downloads/details.aspx?FamilyId=130F7986-BF49-4FE5-9CA8-910AE6EA442C&displaylang=en
I have recently found above link to download
" Microsoft Chart Controls for Microsoft .NET Framework 3.5 "
Actually I was talking about that only.
Wheather it will gimme the option to desing the Charts for the Dashbord
and use them to show the present situation of the comppany.
|
|
|
|
|
Hi,
I'm doing a project that stores present and absent time in the database,
What i need to do now is to calculate the total time the difference between the present and absent time in 'minutes format'.
Can i have an code snippet/example that shows briefly about the time difference calculation? Thanks alot. Looking forward to all experts help.
|
|
|
|
|
How are you storing these 'present' and 'absent' times in your database?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
DateTime presentTime = blah blah blah get values from database
DateTime absentTime = blah blah blah get values from database
TimeSpan difference = presentTime - absentTime;
Console.WriteLine(difference.TotalMinutes);
Simon
|
|
|
|
|
if BODY tag contains onload=window.print() then a PrintDialog is displayed with the page on browser.
I don't want that PrintDialog to be displayed , how to do in c#
|
|
|
|
|
Try the ASP forum.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
sorry guys i have to rewire my question.
I am using Microsoft.Office.Interop.Excel.Application COM to create a Excel spreadsheet, and write the value (not from any dataset) into that spreadsheet, and then StreamWrite to the disk.
For some reason, the following code is not working.
This is the declaration of ws:
Microsoft.Office.Interop.Excel.Worksheet ws =(Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
ws.Cells[1, 1] = "CardNo";
ws.Cells[1, 2] = "PharmacyName";
ws.Cells[1, 3] = "CostPerCard";
sw.Writer(ws.Cells[1, 1]);
sw.Writer(ws.Cells[1, 2]);
sw.Writer(ws.Cells[1, 3]);
I thought this code will write to the spreadsheet like this:
A | B | C
-----------------------------------------------
CardNo | PharmacyName | CostPerCard
but, it wrote to spreasheet like this, all them just in column A:
A
-----------------------------------------------
System.__ComObjectSystem.__ComObjectSystem.__ComObjectH40655
I have been spent quite lots of time on it, but still couldn't work it out.
Thanks heaps
modified on Thursday, May 21, 2009 6:32 AM
|
|
|
|
|
Hi. YOu need to specify a row and Column count. I.e.
int iR, iC;
iR = 4;
iC = 1;
Now, when you write your data you do the following:
objSheet.Cells[iR, iC] = CLIENTSURNAME.Trim();
objSheet.Cells[iR, iC + 1] = CLIENTFORENAMES.Trim();
objSheet.Cells[iR, iC + 2] = TITLE.Trim();
This will move you to the next Column in the current row.
HOpe this helps
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Hi AndieDu
I did not read ur requirement fully.
But i designed the similar code and I got the data from the Database and stored the values
in the excel tablewise.
I think It may help you.
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient ;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Excel_12 = Microsoft.Office.Interop.Excel;
namespace WindowsExcelSheet
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Excel_12.Application oXL;
Excel_12._Workbook oWB;
Excel_12._Worksheet oSheet;
try
{
// Start Excel And get Application Object.
oXL = new Excel_12.Application();
oXL.Visible = true;
// Get a new Workbook
oWB = (Excel_12._Workbook)(oXL.Workbooks.Add(Missing.Value));
oSheet = (Excel_12._Worksheet)oWB.ActiveSheet;
// Add Table Headers going Cell by Cell
//oSheet.Cells[1, 1] = "SaleID";
//oSheet.Cells[1, 2] = "Product";
//oSheet.Cells[1, 3] = "SalePrice";
//Format A1:C1 as Bold, Vertical Alingment = Center.
oSheet.get_Range("A1", "C1").VerticalAlignment = Excel_12.XlVAlign.xlVAlignCenter;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=192.168.10.113;Database=AmitTestData;User ID=sa;Password=sa;Trusted_Connection=False;";
DataSet ds=new DataSet();
Bussiness objBussiness = new Bussiness();
objBussiness.fncReturnDataTable(conn, "select * from BigScreenProducts", ref ds,"Table0");
objBussiness.fncReturnDataTable(conn, "select * from Employee", ref ds, "Table1");
// sqladp1.Fill(ds,"Table2");
int tblIndex = 1;
int AscciVal = 65; // Ascci Value of Capital 'A'
// Table Count
for (int tblNo = 0; tblNo < ds.Tables.Count; tblNo++)
{
// Creating Headings in the Excel
string[] arrcolumn = new string[ds.Tables[tblNo].Columns.Count];
int ColCnt = ds.Tables[tblNo].Columns.Count;
for (int colname=0; colname < ds.Tables[tblNo].Columns.Count; colname++)
{
arrcolumn[colname] = ds.Tables[tblNo].Columns[colname].ColumnName;
}
char start = (char)AscciVal;
char end = (char)(AscciVal + ColCnt-1);
AscciVal = AscciVal + ColCnt+1; // Value set to the next cell of the Excel sheet
int rowCnt = ds.Tables[tblNo].Rows.Count + 1; // Couting no of rows in the current table
oSheet.Cells[1, tblIndex] = "Table" + tblNo.ToString(); // Filling Table Name in the Table
tblIndex = tblIndex - 1;
tblIndex = tblIndex + ColCnt + 2;
oSheet.get_Range(start + "2", end + "2").Value2 = arrcolumn;
oSheet.get_Range(start + "2", end + "2").Font.Bold = true;
string[,] arr1 = new string[rowCnt - 1, ColCnt];
for (int i = 0; i < ds.Tables[tblNo].Rows.Count; i++)
{
for (int j = 0; j < ds.Tables[tblNo].Columns.Count; j++)
{
arr1[i, j] = ds.Tables[tblNo].Rows[i].ItemArray[j].ToString();
}
}
oSheet.get_Range(start + "3", end + rowCnt.ToString()).Value2 = arr1;
}
oXL.Visible = true;
oXL.UserControl = true;
}
catch (Exception theException)
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source);
MessageBox.Show(errorMessage, "Error");
}
}
private void button2_Click(object sender, EventArgs e)
{
}
private void btnStop_Click(object sender, EventArgs e)
{
this.Close();
}
// Function for Manupulate a variable no of columns
//private void DisplayQuarterlySales(Excel_12 oWS)
//{
// Excel_12._Workbook oWB;
// Excel_12.Series oSeries;
// Excel_12.Range oRecizeRange;
// Excel_12._Chart oChart;
// String sMsg;
// int iNumQtrs;
// // Display How many Quaters to Display Data for.
// for(
}
}
------------------------------------------
namespace WindowsExcelSheet
{
class Bussiness
{
public Bussiness()
{ }
public void fncReturnDataTable(SqlConnection conn, string strQuertString, ref DataSet ds, string strTabName)
{
SqlCommand cmd=null;
SqlDataAdapter sda=null;
try
{
cmd = new SqlCommand();
cmd.CommandText = strQuertString;
cmd.Connection = conn;
cmd.Connection.Open();
sda = new SqlDataAdapter(cmd);
sda.Fill(ds,strTabName);
}
catch (Exception Exp)
{
}
finally
{
cmd.Connection.Close();
cmd.Dispose();
cmd.Dispose(); sda.Dispose();
}
}
}
}
|
|
|
|