|
Yes this is approximately what I need, with the "using project=namespace.project" statement beeing outside the code file, so I do NOT have to change the content of the code file in each project using it ...
|
|
|
|
|
This should be really simple, but im having one of those mornings...
Im trying to close my connection, but its staying open
if (Border.BLL.Inventory.SqlConnect.GetConnection().State == ConnectionState.Open)
{
Border.BLL.Inventory.SqlConnect.CloseConnection();
}
//BLL
public static SqlCeConnection CloseConnection()
{
return DAL.Helpers.SQLconnect.CloseConnection();
}
//DAL
public static SqlCeConnection GetConnection()
{
SqlCeConnection conn = new SqlCeConnection();
try
{
conn.ConnectionString = Helpers.ConnectionCommand.ConnectionString;
conn.Open();
return conn;
}
catch(Exception e)
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
Border.Model.Helpers.FileWriter.Write(e.ToString(), true);
}
return conn;
}
public static SqlCeConnection CloseConnection()
{
try
{
if (GetConnection() != null)
{
if (GetConnection().State == ConnectionState.Open)
{
GetConnection().Close();
}
}
return GetConnection();
}
catch (Exception e)
{
if (GetConnection().State == ConnectionState.Open)
{
GetConnection().Close();
}
Border.Model.Helpers.FileWriter.Write(e.ToString(), true);
}
return GetConnection();
}
|
|
|
|
|
Please put your code in <pre> tags, it is currently difficult to read.
consider using the following snippet:
using(SqlCeConnection connection = GetConnection())
{
}
as this will close the connection automagically for you, even if the database call throws an exception.Dalek Dave: There are many words that some find offensive, Homosexuality, Alcoholism, Religion, Visual Basic, Manchester United, Butter.
Pete o'Hanlon: If it wasn't insulting tools, I'd say you were dumber than a bag of spanners.
|
|
|
|
|
Hi,
I went through your code, and got a point to tell you if that helps. I noticed that in catch block in DAL you are closing the connection only if the connection state is OPEN. I remember there is another option that you may also check before you are closing the connection and that is BROKEN. So what I am suggesting is ,
if ((GetConnection().State == ConnectionState.Open)||((GetConnection().State == ConnectionState.Broken))
{
GetConnection().Close();
}
or
if (GetConnection().State != ConnectionState.Closed)
{
GetConnection().Close();
}
Give a try and let me know.Thanks,
Arindam D Tewary
|
|
|
|
|
Arindam Tewary wrote: if ((GetConnection().State == ConnectionState.Open)||((GetConnection().State == ConnectionState.Broken))
This isn't a good idea since his code is returning a new connection object on every call to GetConnection. It's not returning the same connection object, but a new one every time. So, you're comparing the first connections .State to Open OR the second connection objects state to Broken. It's not doing what you think it's doing.
|
|
|
|
|
doh!
thanks that makes perfect sense.
|
|
|
|
|
I deduce inquiry data from data base in dataGridView (on image) I wish to deduce these data in Excel as on the image. How to me it to make?
http://www.cyberforum.ru/windows-forms/thread105166.html#post601894
|
|
|
|
|
I use one image as the background picture. But when open the form, it shows so slow.
How to solve it ?
|
|
|
|
|
What are the things you are doing when the form is loading? Is it possible to move some of that to another thread?
You can also use a splash screen and display the form only when all the operations are done.
|
|
|
|
|
Only initialize 20 controls, in which a circle is drawed.
I try to delete background image, the form shows more quickly.
So , it must the background image's problem.
I am trying your solution,
thanks very much.
|
|
|
|
|
I wonder if you are shrinking the image to fit, or should I say, .Net is shrinking it to fit.
Check the actual size of the image and resize it to no larger than your form.
You could also try some of the tricks from the html world, for example if you are aiming for a gradient fill, use a 1 pixel wide image and stretch it.
|
|
|
|
|
Thanks for your reply.
I donot shrink this image. but I only set the image as the background image of the form, perhaps this form's size is not equals to this image's size, when OnPaint it need use much time to let the image size to fix the form's size?
I put many control in the forms, such as panle. I set these control's backcolor as transparent.
Does the backcolor's transparent cost much time?
|
|
|
|
|
20 controls should not slow things drastically down. As the other reply mentions, check the image size and resize it to your needs.
The type of file also matters. A bitmap file will be of a way more size (Bytes) than a same sized (dimension) JPG or JPEG.
|
|
|
|
|
The image is about 30kB in JPEG format, I will try to minish its size.
|
|
|
|
|
|
You should read the sticky post "How to get an answer to your question".
In the Main method or in the main form's load event, check the processes running. If it contains your application, exit and display a message that application is already running.
|
|
|
|
|
Thanks big friends you have very much helped me.
|
|
|
|
|
arsendem wrote: Hi
Uh... yeah... Hi.Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
i'm trying to understand the usage of settings.setting file, it says u can only change user scoped data at runtime and application scoped data cannot be changed at runtime, to modify the application scope data i have to use the assembly.exe.cofig file . but in my application it isn't there . how can i create it
|
|
|
|
|
|
Hi,
You can right-click on your project (from the solution explorer) and choose Add-->New Item and select Application Configuration File from the dialog box that pops up and click OK. This will add an App.Config file to your project. This will be automatically renamed to Assembly.exe.config when you run your application.
You can use the same XML data as given in the link to the post that d@nish had posted.
Also, if you use
string test1 = System.Configuration.ConfigurationSettings.AppSettings["Key1"];
in your code, the VS compiler might throw a warning that this is deprecated.
To get through that warning, Add reference to System.Configuration component in your project and use :
string test1 = System.Configuration.ConfigurationManager.AppSettings["key1"];
Hope this helps.
Thanks,
Ram
|
|
|
|
|
HI,
I would like to make a small C # application with the overlay video. Can someone help me with a small example?
Thank you!
|
|
|
|
|
|
An event calls method A in some cases and method B in others.
Both A and B return a string.
The event handler returns void.
How do I write the return value from the right method to a textbox in my main Window?
|
|
|
|
|
What event? Where is it called from? It would help if you showed something a little more concrete.
public void SomeEvent(object sender, EventArgs e)
{
if(whatever)
textbox1.Text = MethodA();
else
textbox1.Text = MethodB();
} I know the language. I've read a book. - _Madmatt
|
|
|
|