Hi folks,
I'm trying to write a service in CBuilder 6 (target XP Pro). Part of this service's job is to monitor and update a table on a database. We use direct ODBC to connect to the database, but the problem is happening with ADO as well, so we'll use that for simplicities sake.
You can see my code below. This is called from a function which is executed in the ServiceStart event.
My issue is, I'm not able to get a connection. Our MSSQL DB uses domain authentication, so I have tried running the service using my domain account. I've also tried explicitly defining my domain\username and password but that doesn't work either (in the properties for the service, log on tab).
Can anyone at all help me with this? Anything at all is appreciated.
Another question I have is how would one debug a service? I have remote debugger installed. Do I spawn the process using something like rundll32.exe or something? Again, any help appreciate.
Many thank in advance
Stu.
Code Snippet:
TADOConnection* DB = new TADOConnection(this);
try
{
DB->ConnectionString = "Provider=MSDASQL.1;Password=password;Persist Security Info=True;User ID=usernamej;Data Source=datasource";
DB->Connected = true;
returnValue = DB->Connected;
ShowMessage("Connected");
}
catch (Exception &exception)
{
ShowMessage("Not COnnected");
}
Notes: The connectionstring property is indicative only and has had the username, password and database changed. Using this string in a standalone application results in a consistently successful connection and data can be fetched using a query.
In Response to JP:
Hi JP.
Thanks for your comment. I'm actually not getting an exception thrown here (which is strange). I modified the code (see below) to include a few more msgboxes and the only one I see is the first one - attempting connection.
ShowMessage("Attempting Login");
TADOConnection* DB = new TADOConnection(NULL);
try {
ShowMessage("1");
DB->ConnectionString = "<as before>";
ShowMessage("2");
DB->Connected = true;
ShowMessage("Connected");
} catch (Exception &exception) {
ShowMessage(exception.Message);
ShowMessage("Not COnnected");
}
Any ideas? I cant see why the connection component isn't even being created (note I tried changing the owner from this to NULL as well just to see what would happen).
Thanks!
Stu.