How to Debug Window Service without installing
Posted by: admin in .NET, Window Services on September 3rd, 2010
Usually if we want to debug the windows service project to see if it is behaving as we expected, what we do is by installing the windows service and attaching that project to the process.
There is also another way to debug without installing it, what we need to do is by creating another project such as console project then copy and paste the code below.
-
Sub Main()
-
#If Not Debug Then
-
Dim servicesToRun As System.ServiceProcess.ServiceBase()
-
-
servicesToRun = New System.ServiceProcess.ServiceBase() {New MyService()}
-
System.ServiceProcess.ServiceBase.Run(servicesToRun)
-
#Else
-
Dim service As AS2Client.AS2SenderService = New MyService()
-
service.myentrysub()
-
-
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
-
-
#End If
-
-
-
-
End Sub
References:
Run Windows Service as a Console program
How to find the CONSTRAINTS of table in SQL Server
Posted by: admin in Constraint, Database on August 26th, 2010
Below is the query on finding the constraints of the table
-
select * from sys.objects where parent_object_id = object_id(N'tblDemographic01Def')
Operand type clash: nvarchar(max) is incompatible with image
This error usually occurs when you are adding / updating a record on the database table with image/binary columns, and the value of that image column is null and you did not specify the data type of the parameter.
To resolve this issue you need to explicitly specify the datatype of that image/binary column because the default data type of the Sql parameter is varchar(string)
How to Capture form without showing it in .Net
-
using System;
-
using System.Drawing;
-
using System.Runtime.InteropServices;
-
using System.Windows.Forms;
-
-
public class ControlPainter
-
{
-
private const int
-
WM_PRINT = 0×317, PRF_CLIENT = 4,
-
PRF_CHILDREN = 0×10, PRF_NON_CLIENT = 2,
-
COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;
-
-
[DllImport("USER32.DLL")]
-
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);
-
-
public static void PaintControl(Graphics graphics, Control control)
-
{ // paint control onto graphics
-
IntPtr hWnd = control.Handle;
-
IntPtr hDC = graphics.GetHdc();
-
SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);
-
graphics.ReleaseHdc(hDC);
-
}
-
}
-
-
<strong>TO USE IT:
-
</strong>
-
using (Form f = new MyForm()) {
-
Image i = new Image(f.Width, f.Height);
-
Graphics g = Graphics.FromImage(i);
-
ControlPainter.PaintControl(g, f);
-
}
How to get the difference between two dates in .net
Posted by: admin in .NET, Date and Time on August 10th, 2010
You can use the built-in function for getting the difference between two dates.
Example:
-
Dim d1 As DateTime = Now
-
Dim d2 As DateTime = Now.AddDays(3)
-
-
Dim m As TimeSpan = d2.Subtract(d1)
-
Dim t As String
-
-
t = "Days : " & m.Days.ToString() & vbCrLf
-
t += "Hours : " & m.Hours.ToString() & vbCrLf
-
t += "Minutes : " & m.Minutes.ToString() & vbCrLf
-
t += "Seconds : " & m.Seconds.ToString() & vbCrLf
-
t += "Milliseconds : " & m.Milliseconds.ToString() & vbCrLf
-
MessageBox.Show(t)
How to convert .net Form to Image
-
Public Class Form1
-
-
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
-
CreateBitmap(Me)
-
End Sub
-
-
Private Sub CreateBitmap(ByVal con As Control)
-
'Dim g As Graphics = Me.CreateGraphics()
-
-
Dim b As Bitmap = New Bitmap(Me.Width, Me.Height)
-
Me.DrawToBitmap(b, New Rectangle(0, 0, Me.Width, Me.Height))
-
-
b.Save("test.jpg", Imaging.ImageFormat.Jpeg)
-
b.Dispose()
-
'g.Dispose()
-
End Sub
-
End Class
sn.exe Access is denied
You can do this by running the command prompt as a administrator, just right click and run as administrator.
You can also refer to the following link if the above solution does not work:
- sn.exe fails with Access Denied error message
- How To Create an Assembly with a Strong Name in .NET Framework SDK
Convert color to string
To convert a color to a string use the ColorConverter class but this can be access through TypeConverter class;
-
Dim myColor as Drawing.Color = Color.Red
-
-
Dim clor As System.ComponentModel.TypeConverter = System.ComponentModel.TypeDescriptor.GetConverter(myColor)
-
dim ColorName as string
-
-
ColorName = clor.ConvertToString(Color.Red)
Convert color from string
To convert a color from a string use the ColorConverter class but this can be access through TypeConverter class;
-
Dim myColor as Drawing.Color
-
-
Dim clor As System.ComponentModel.TypeConverter = System.ComponentModel.TypeDescriptor.GetConverter(GetType(Drawing.Color))
-
-
myColor = clor.ConvertFromString("Blue")
MyColor variable is now ready to use.
An error occurred while validating. HRESULT = ‘80004005′
Posted by: admin in .NET, Deployment, Exception on July 27th, 2010
An error occurred while validating. HRESULT = ‘80004005′, this error just came up when I’m trying to organize my .Net Project files in my Solution, I removed some of the projects and just use the compiled dll in referencing to the main Project. However, this error has appeared during rebuilding the setup project and it took some of my time to find the solution or the cause.
So, what I did was I removed all References from the Target Primary Output project and added them and rebuilding it again ,
that’s it no more errors.
“Thank you for reporting this issue. We were able to reproduce the problem and have identified the root cause. The problem is caused by cross-solution project reference between Solution1 and Solution2. From the attached project, the project “WindowsFormApplication1” in Solution2 references a project that is not in Solution2 (it references ClassLibrary1 from Solution1). To fix the error, the workaround is to copy the ClassLibrary1 project to Solution2 and re-add the reference to ClassLibrary1 within its own solution.
Project-to-project references only works within the same solution. If you have to split into two solutions and split the code for your class library into two projects, you need to also split the project that references the class library into two projects (one for each solution) in order to avoid project references outside the current solution.
I hope this helps.
Candy Chiang
Program Manager – Visual Studio”
For more information and explanation about this error just click here