|
Windows services run with the current app directory set to %SYSTEM32%, which can cause problems if you are reading your connection string from an external config file. To see if that is the case, try copying your config file to the %SYSTEM32% directory.
my blog
|
|
|
|
|
Yes, I have MDAC 2.8 installed on machines. I do not have a stack trace and I have hard coded the connection string in the program.
Its a very strange problem, because when I make it a Windows Application rather than a Windows Service, it works perfect.
My database server is running WinXp with SP2 and SQL Server 2000 with SP3, and my client machine is running Windows 2000 with SP3.
Same is the problem with the file access. I am trying to access a text file on a client machine with UNC address. The Windows Service is not starting. When I copy the same code on a Windows Appliaction, it is working fine. The Service does not have any problem with text file on the local drive.
Regards,
Zishan
|
|
|
|
|
Zishan wrote:
Same is the problem with the file access. I am trying to access a text file on a client machine with UNC address. The Windows Service is not starting. When I copy the same code on a Windows Appliaction, it is working fine. The Service does not have any problem with text file on the local drive.
I agree with Daniel that you should modify your program so it saves a stack trace in case of an unhandled exception and if I were system administrator and had to use your service I would expect it to write everything relevant into the Windows logs.
Without a stack trace however I can just give you my next best guess. And because you say that the service can access local files but can't access remote files with UNC paths then I'd say you're getting some kind of access denied exception. Remember that when you execute your code as a normal exe (and don't use run as) it runs with your permissions. As developer I assume you might have administrative privileges on your local machine and maybe even on the servers. Your service however runs with the permissions of the account you set in the service configuration. That's by default LOCAL_MACHINE\SYSTEM. Of course any local system account has no privileges on any remote machine. Even if it indeed is an domain account you setup for your service it might not have enough permissions to access the data you want to use. So check out your service configuration and see if that's the problem.
Best regards
Dennis
P.S. Why are you posting as Anonymous? Don't you have an account or are you just not logged in. Well, it's not like it really bothers me, but I'm curious to whom I'm writing.
|
|
|
|
|
Yes, that was an Access Denied error. I changed the service configuration to NT AUTHORITY/NetworkService and that started. Thanks for your help
Zishan
PS : I had an account here but I was too lazy to log in.
|
|
|
|
|
Hello all,
I am working on a program that displays descision trees in a panel control. The links between the nodes are drawn straight on to the panel whereas the nodes are custom controls.
Trying to print the contents of the panel I have used GetImage, unfortunately this only gives me the links and not the nodes. I suspect having studied further I should have drawn the whole lot to a graphics path... any way I can bodge it without rewriting all the graphics code? I wish to keep the custom controls as they allow me to process mouse events easily.
Rob
|
|
|
|
|
What you could do is create an Image object (as a member of your form class), give that to the PictureBox's Image property, then do all your drawing operations onto the Image itself instead of the picturebox (you can get a Graphics handle just as easily from the Image, so your code should need only minor modifications)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
That would be a complete waste of memory and CPU cycles. The OnPaint virtual function and the event if fires - Paint - exist so that you can draw onto any control. Drawing into an images then assigning that images to a PictureBox is inefficient and requires much more memory than drawing on the control's surface itself. That can be done with a simple Panel as the poster is currently doing.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You can write any window to a DC using Windows API as it's being shown on the screen. You first need to call CreateDC("DISPLAY", null, null, null) and then use SendMessage to send a WM_PRINT to the window.
Alternatively, you'll need to rewrite your code and draw everything on the Panel's OnPaint.
Yes, even I am blogging now!
|
|
|
|
|
Extending on what Daniel said, you should rewrite your OnPaint to paint the entire surface (nodes and lines) but in a modular manner that you can pass a Graphics object (and perhaps the clip bounds) to paint on, but don't paint directly in OnPaint . This allows you to pass the Graphics for a PrintDocument (or even an HDC for some other device using Graphics.FromHdc ) and use the same drawing routines.
The common solution follows:
private void Paint(Graphics g, Rectangle bounds)
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Paint(e.Graphics, Bounds);
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
Paint(e.Graphics, e.PageBounds);
} Handling your mouse events isn't too hard if you design a nice abstract system of nodes where the Panel may translate mouse events to the nodes, but the nodes actually contain the code to move themselves. Polymorphism is a very powerful tool.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I want to do something when all the threads have been excuted,but I don't know how to detect this event.Can you tell me?
|
|
|
|
|
One very simple solution would be to create an array of bools that all the threads and your main process can see - each thread knows it's number (set by the main process when the thread starts) and when each thread finishes it sets it's relevant entry in the array to true.
Then the main process just needs to sporadically check the array, to see if they've all finished (and find out which thread it's waiting for)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Common solutions are:
1. Array of bools or a bool property on each thread controlling object (only if you need to know which threads are still running).
2. Static counter that gets incremented when each thread finishes.
3. Thread.Join each thread.
4. Use a synchronization object, e.g., an ManualResetEvent (my favorite).
Whatever solution you chose, don't forget to put robust exception handling, or your program will wait forever in case of an exception.
Yes, even I am blogging now!
|
|
|
|
|
Hi! I want to make NB shared folders scanner on C#.
How should I do this? Using netapi32.dll or perhaps, you could propose better choise??
PS: I'm sorry 4 my English$)
|
|
|
|
|
Start by enumerating the servers and workstations on the network using the NetServerEnum API exported by netapi32.dll. For each machine, enumerate its shares using the NetShareEnum API.
An example of using NetServerEnum can be found here[^].
See the Platform SDK for both NetServerEnum and NetShareEnum documentation at http://msdn.microsoft.com/library[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
How i can fire(run) an event on a DataGrid cell?
|
|
|
|
|
It depends on the type of cell...if it's just a normal text box, then you can handle the event on the textbox itself...
|
|
|
|
|
How do you get the CurrentCell's text box from the data grid?
Greg Bayard
|
|
|
|
|
I use DataGridTimePickerColumn(class in msdn) style DataGrid column, when I edit grid cell ,it work well ,but when i insert new row,it has error of data convert,how i do?
|
|
|
|
|
More than likely (since you didn't give any details about the exception being thrown to you) need to define a default value for the column that you use the DataGridTimePickerColumn class. The value it displays - a DateTime - is a value type and cannot be null. You could optionally check for DBNull.Value in your code (modify the example: it's only an example anyway) and either assign a default value then or handle it however you want.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot!
this my code
DataGridTimePickerColumn tpcsCreatedDate = new DataGridTimePickerColumn();
tpcsCreatedDate.MappingName = "CreatedDate";
tpcsCreatedDate.HeaderText = "CreatedDate";
tpcsCreatedDate.NullText = DateTime.Now.ToShortDateString();
myGridStyle.GridColumnStyles.Add(tpcsCreatedDate);
this is DataGridTimePickerColumn from msdn
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
// This example shows how to create your own column style that
// hosts a control, in this case, a DateTimePicker.
public class DataGridTimePickerColumn : DataGridColumnStyle
{
private DateTimePicker myDateTimePicker = new DateTimePicker();
// The isEditing field tracks whether or not the user is
// editing data with the hosted control.
private bool isEditing;
public DataGridTimePickerColumn() : base()
{
myDateTimePicker.Visible = false;
}
protected override void Abort(int rowNum)
{
isEditing = false;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
Invalidate();
}
protected override bool Commit
(CurrencyManager dataSource, int rowNum)
{
myDateTimePicker.Bounds = Rectangle.Empty;
myDateTimePicker.ValueChanged -=
new EventHandler(TimePickerValueChanged);
if (!isEditing)
return true;
isEditing = false;
try
{
DateTime value = myDateTimePicker.Value;
SetColumnValueAtRow(dataSource, rowNum, value);
}
catch (Exception)
{
Abort(rowNum);
return false;
}
Invalidate();
return true;
}
protected override void Edit(
CurrencyManager source,
int rowNum,
Rectangle bounds,
bool readOnly,
string instantText,
bool cellIsVisible)
{
DateTime value = (DateTime)
GetColumnValueAtRow(source, rowNum);
if (cellIsVisible)
{
myDateTimePicker.Bounds = new Rectangle
(bounds.X + 2, bounds.Y + 2,
bounds.Width - 4, bounds.Height - 4);
myDateTimePicker.Value = value;
myDateTimePicker.Visible = true;
myDateTimePicker.ValueChanged +=
new EventHandler(TimePickerValueChanged);
}
else
{
myDateTimePicker.Value = value;
myDateTimePicker.Visible = false;
}
if (myDateTimePicker.Visible)
DataGridTableStyle.DataGrid.Invalidate(bounds);
}
protected override Size GetPreferredSize(
Graphics g,
object value)
{
return new Size(100, myDateTimePicker.PreferredHeight + 4);
}
protected override int GetMinimumHeight()
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override int GetPreferredHeight(Graphics g,
object value)
{
return myDateTimePicker.PreferredHeight + 4;
}
protected override void Paint(Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum)
{
Paint(g, bounds, source, rowNum, false);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
bool alignToRight)
{
Paint(
g,bounds,
source,
rowNum,
Brushes.Red,
Brushes.Blue,
alignToRight);
}
protected override void Paint(
Graphics g,
Rectangle bounds,
CurrencyManager source,
int rowNum,
Brush backBrush,
Brush foreBrush,
bool alignToRight)
{
DateTime date = (DateTime)
GetColumnValueAtRow(source, rowNum);
Rectangle rect = bounds;
g.FillRectangle(backBrush,rect);
rect.Offset(0, 2);
rect.Height -= 2;
g.DrawString(date.ToString("d"),
this.DataGridTableStyle.DataGrid.Font,
foreBrush, rect);
}
protected override void SetDataGridInColumn(DataGrid value)
{
base.SetDataGridInColumn(value);
if (myDateTimePicker.Parent != null)
{
myDateTimePicker.Parent.Controls.Remove
(myDateTimePicker);
}
if (value != null)
{
value.Controls.Add(myDateTimePicker);
}
}
private void TimePickerValueChanged(object sender, EventArgs e)
{
this.isEditing = true;
base.ColumnStartedEditing(myDateTimePicker);
}
}
please give me some more help!
|
|
|
|
|
I invoked the format command of OS(XP) in my code.But evry time it display a console window and I have to click the Enter key to go on the function. So,I wonder if there is a way to perform carriage return automatically and we do not need to click the Enter key?
Thanks for help!
|
|
|
|
|
|
Have you tried?
echo. | format a:
I don't know if it'll work, but give it a try. It's old DOS redirection, you are redirecting the ouput of the ECHO command (a carraige return) to the input of the FORMAT command.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi,
Sometimes the datagrid control is updating very slowly for some reason. In my program i have these circle objects and whenever the user clicks on one, the following occurs:
1. I create new DataRows for information contained in the circle clicked.
2. The rows are added to the DataTable bounded by the DataGrid.
3. When a different circle is clicked, the DataTable clears and the following steps are repeated.
The delay only seems to occur when a circle is clicked for the first time, each initial circle clicked on seems to update without a hitch.
Is this a cache issue? Thanks for the help!
Brian
|
|
|
|
|
Hello!
I´m new to C# and have a question for the pro's.
Is it possible to put an ArrayList into another ArrayList like a 2d array?
How would the code look like?
Regards.
stumpi
|
|
|
|
|