Monday, February 13, 2012

ArgumentNullException thrown after second connection

Hi,

Our application has two parts: one is Windows application and the other

one is Windows service. The service runs under Local system accont. We

use third party application to log into database which uses instance of

SQL Server 2005 Express . We use same methods for logging for Windows

application and for Windows service. Both, application and the service

are compiled with .Net framework 2.0 and VS 2005 (C#).

The application always logs into the database succesfuly. The problem

is with the service. The code for the service works like this: first

login into database to retrieve some data, after that log off and

disconnect, and after that immediately tries to login again using the

the same credentials. The first login is always succesful, but the

second one fails with error message:

Type:System.ArgumentNullException

Message:Value cannot be null.

Parameter name: Value is

null.

If we set the Service to run under User windows

account - everything works fine. Does anyone have similar

problems? What can be the problem here? Can anyone help me?

Thanks.

Could you provide the code that is causing the problem and identify the line that thows the exception?

Mike

|||The code is below. The same code works fine for the windows application

and when service connects for the first time. Database path, user name

and password are the same. The code crashes when Windows service tries

to connect for the second time (after LogOff) on line framework.LogOn( sDatabaseFullPath, sUserName, sUserPassword ) and it throws Exception:

Type:System.ArgumentNullException

Message:Value cannot be null.

Parameter name: Value is

null.

Parameters are not null, not even empty string. They contain valid string values (I checked with the debugger).

Framework is namespace from the third party application SDK. I

contacted this third party support also, but they didn't try to help me.

Please note that this code was working fine with .Net framework 1.1, VS 2003 and SQL Server 2000 DE.

public override void LogOn( DBCredentials dbCredentials

)

{

string sDatabaseFullPath =

dbCredentials.DBFileNameFullPath;

string sUserName =

dbCredentials.UserName;

string sUserPassword =

dbCredentials.Password;

try

{

if( IsConnectionLive

)

framework.LogOff();

framework.LogOn(sDatabaseFullPath, sUserName,

sUserPassword);

}

catch( InvalidLogonException

ile )

{

throw new InvalidLogonException(

ile.Message, dbCredentials);

}

catch( ThreadAbortException

ex )

{

throw

ex;

}

catch( LockDatabaseException lde )

{

throw new LockDatabaseException(

lde.Message );

}

catch( Exception

ex)

{

throw new Exception(

ex.Message );

}

}

|||

I don't know anything about this framework namespace or what happens when you call framework.LogOn so it's tough to give you any advice. If you can look at the code in framework, that would be a place to start, if you can't, you'll likely need to push back on the vendor that sold you this framework as this seems to be a problem with their code. There is likely something within framework that is causing the ArgumentNullException and it is just bubbling up.

As a troubleshooting measure, you could try creating your own LogOff and LogOn procedures and use them in your service. You need to try and isolate the "black box" and ensure that SQL Server is working correctly and that the action you are trying to perform is working without the call to framework.

Mike

|||Thanks.

No comments:

Post a Comment