|
Hi All,
after updating the remote access priviliges of my sql server,
I am restarting the MSSQLSERVER using this code:
ManagementObject svc ... finding MSSQLSERVER
...
svc.Get();
if ((uint)svc.GetPropertyValue("State") != sqlServiceStopped)
{
svc.InvokeMethod("StopService", null);
svc.InvokeMethod("StartService", null);
}
I also start the SQLAgent process that stops when stopping the MSSQLSERVER.
I can see that all the processes are up and running, but my application
fails at the ExecuteReader line:
sqlConnection = new SqlConnection(connectionString);
sqlConnection.Open();
SqlCommand sqlCommand = new SqlCommand("select xx from xxs",sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(CommandBehavior.CloseConnection);
this is the exception that I am getting:
{"A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)"}
Why is that ?
What should I do to over come it ?
Thanks
Calanit
|
|
|
|
|
Perhaps you need to wait for the SQL Server service to completely start before executing a query against it?
You would probably need to run a test query against the database every so often until either the query succeeds or a timeout in your code is exceeded. This will tell you that the server is completely up or hasn't come up yet.
|
|
|
|
|
Thanks Dave, But ...
I tried waiting with the debugger.
I can see in the SQL server configuration manager that all processes are back, up and running.
If I stop my application and start it again, I am not getting this problem, therefor I don't think it's a problem of waiting ...
It looks like I am losing a connection between my application and the SQL Server - but I am not holding such a connection ... ?!
|
|
|
|
|
never mind, I just read your reply to Dave
led mike
|
|
|
|
|
I just found in another forum (sorry ), that if I catch the transport-level error and run the query again - it will work.
I tried it, and it does work, but I don't like this solution and do not understand it.
Does someone have an idea to way it is and how to solve this nicely ?
Thanks
Calanit
|
|
|
|
|
The only thing I can think of is finding some way of telling ADO.NET to drop it's [pooled] connections to the SQL Server and start creating new ones.
EDIT:
Actually, there's a great little article on connection pooling, and a section on exactly what you're facing right here on CP. Click[^]
|
|
|
|
|
Dave - You did it !
I used: sqlConnection.ClearAllPools() after restarting the SQL server process and every thing works like magic.
Thanks !
Calanit
|
|
|
|
|
I'm using several labels located next to each other thanks to left docking and the autosize property.
The thing is, even if you set margin/padding to 0, there's still a margin:
Picture explaining the problem:
http://uppix.net/5/1/2/69b945ab92a5598fb93aca1d50be6.jpg[^]
How to get rid of this?
I'm using labels because each label can have a different color/font/ The RTF box is a no go as it doesn't have any autosize property and it doesnt behave like a label (you can select the text). "RTF label" control on this website doesnt have the autosize property and you can still select the text...
|
|
|
|
|
You could write your own label class that simply overrides the base paint method.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You can't get rid of it.
If this is a problem, why even use a Label? Why not just render the text yourself with DrawString? You'd probably end up doing the same thing if you made your own Label control and supplied your own drawing code anyway.
|
|
|
|
|
I can't use DrawString because I need to know the exact length of the text: that's why the autosize property is so convenient. I just set the texts of the labels and add the width properties to know the final length of all the labels.
If I'm using DrawString or something that overrides the WM_PAINT of the label, how do I know the length in pixels of the text?
|
|
|
|
|
Tony_P wrote: I can't use DrawString because I need to know the exact length of the text
That's what MeasureString is for.
|
|
|
|
|
Alright I've just found this in the meantime. Thank you for your time!
|
|
|
|
|
this is what I came up with:
public class EnhancedLabel : Label
{
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush fore = new SolidBrush(this.ForeColor);
Brush back = new SolidBrush(this.BackColor);
SizeF s = g.MeasureString(this.Text, this.Font);
this.Width = (int)s.Width;
this.Height = (int)s.Height;
g.FillRectangle(back, this.Left, this.Top, this.Width, this.Height);
g.DrawString(this.Text, this.Font, fore, this.Location);
}
}
|
|
|
|
|
And a version 2.0, much better ;o
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Brush fore = new SolidBrush(this.ForeColor);
Brush back = new SolidBrush(this.BackColor);
g.FillRectangle(back, this.Location.X, this.Location.Y, this.Width, this.Height);
g.DrawString(this.Text, this.Font, fore, Point.Empty);
}
protected override void OnTextChanged(EventArgs e)
{
Graphics g = System.Drawing.Graphics.FromHwnd(this.Handle);
SizeF s = g.MeasureString(this.Text, this.Font);
this.Width = (int)s.Width;
this.Height = (int)s.Height;
base.OnTextChanged(e);
}
|
|
|
|
|
Just a couple of points - You should dispose of your brushes, or better still put them in using blocks.
using (Brush back = new SolidBrush(ForeColor))
{
e.Graphics.FillRectangle(back, Location.X, Location.Y, Width, Height);
}
using (Brush fore = new SolidBrush(BackColor))
{
e.Graphics.DrawString(Text, Font, fore, Point.Empty);
}
You can use the Size struct's static Round method to convert the SizeF
Size = Size.Round(s);
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)
|
|
|
|
|
Right, thank you for the tips. I used the brushes without even checking if it was a disposable object. Shame on me.
|
|
|
|
|
Hi,
the most expensive one, the one you really should dispose of, is the result of Graphics.FromHwnd()
for the brushes, you might consider keeping them in a class member, rather than creating and disposing them all the time.
creating a Graphics, as you do, is something I avoid even at modest cost; so I am not in favor of
your 2.0 solution; instead I would do everything in OnPaint, possibly do MeasureString inside
a test on text changed.
|
|
|
|
|
Well the problem is that I need the width/height of the label without painting it, so I can't do everything in the paint event.
The best way is probably to store the brushes, for sure.
Can I store the Graphics.FromHwnd() the same way or can the value of Graphics.FromHwnd() change?
|
|
|
|
|
Tony_P wrote: I need the width/height of the label without painting it
Huh? if you need it inside OnPaint only, then do the MeasureString in OnPaint just before you
use DrawString. if you need its result outside OnPaint, I would try and execute OnPaint once
before you need the sizes.
Keeping a Graphics does not feel right; for one it is an expensive object, and it contains many things that may be different each time you get a graphics; e.g. every time you move ab object over a Form, the Form may get Paint events with varying clip regions in the Graphics object. Also the user might change the resolution of the screen, and whatever more.
|
|
|
|
|
Why don't you just write a function that does something like this:
class BlahBlah
{
SizeF m_textSize;
public SizeF MeasureText(string text)
{
(using Graphics graphics = Graphics.FromHwnd(this))
{
m_textSize = graphics.MeasureString(text, someFont);
}
return m_textSize;
}
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I will do such things only if I see no reasonable alternative; I try and avoid creating a new Graphics as much as I can. In OnPaint the Graphics is for free, so why not take advantage of that one?
In the few 100K lines of C# code I have at hand, I found only two instances of Graphics.FromHwnd;
I do use Graphics.FromImage of course when drawing onto a Bitmap, there simply is no alternative there.
|
|
|
|
|
i can't access my MSN application ID in my project.I created APPID and added the web refernce.When i run and click on submit it's going in catch and refershing the page.
|
|
|
|
|
I don't think anyone here knows what you're talking about. MSN AppID?? What AppID?? What web reference to what service?? Submit?? Submit what to where??
Also, you may want to re-ask this question in the ASP.NET Forum.
|
|
|
|
|
I have a status strip which displays a progress bar during initialization and execution phases of my application.
In the designer I set Max=100 Min=0 Step=10
The bar progresses as expected, but when I reach completion I set the bar value to 100, put out my complete message, and sleep the thread for 1 second. The Progress bar is always showing only about 80% of the progress bar painted.
I've experimented by taking the value to 101 (for example) and it doesn't like that. I've also paused the code and validated that the value is indeed set to 100.
Has anyone experienced this or (better yet) figured out how to fix this?
Thanks in advance.
|
|
|
|