MS SQL Server :: Null Reference Exception

I  am running into a null reference exception on replication with SQL Server 2005. The problem occurs at synchronize process.
Exception shows as "an unexpected error has occurred in AppName.exe. Select Quit and then restart this program, or select Details for more information.
I think the problem is in SQL Server, because after restarting SQL service synchronization works for an hour and after the problem start again. I've tried to increase remote query time from 600 to 6000 but doesn't  help  either
Here is detail of my pocket PC (in case if you need them)
Device O/S: Windows Mobile 5.0 v 5.1.195 Build 14957.2.3.1
Hardware: Dell Axim X51v, Intel PXA270

Any ideas on this?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan McCauleyEnterprise Analytics ManagerCommented:
It's impossible to tell from what you've posted here. A NullRefernceException occurs when you declare a variable, but then try to use it before it's been assigned a value (or after the value has been cleared).

Can you post the code where the exception occurs (you should be able to see where it's being caused in the Stack Trace in your event)? If possible, all the code between the line the causes the exception (at the end) and the variable's declaration (at the beginning) would be a good starting place for seeing what's causing this exception.
hjgodeTier 3 Senior Technical Support EngineerCommented:
You wrote about using SQL Server replication, I assume with SQL Sercer CE compact. Are you using RDA (PULL, PUSH, SqlCommand) or Merge replication?

How is the device powered?

Is it connected via a cabled (Ethernet) or wireless Lan or via ActiveSync to the SQL Server?

You may enable Logging or just take a look for the log files at the virtual directory of the SQL servers publication. Take a look in the SQL CE Agent logs, the SQL Server and the Server logs.
artakamiAuthor Commented:
here is the details of error from pocket PC.


   at System.Web.Services.Protocols.SoapHttpClientProtocol.doInvoke(String methodName, Object[] parameters, WebClientAsyncResult asyncResult)
   at EzRoute.lerch.EzRouteService.GetChangedProducts(Int32 lastRun, String lastSalesperson)
   at EzRoute.Synchronize.btProceed_Click(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
   at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
   at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
   at System.Windows.Forms.Application.Run(Form fm)
   at EzRoute.MSR.Main()

Thats what i could get from it.
also, if needed , i can provide log or any data from MS SQL server.
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

hjgodeTier 3 Senior Technical Support EngineerCommented:
Thta does not look like SQL to me. This looks like a webservice request that fails. The route cause may be a faulty SQL query, but that is not in focus here.
artakamiAuthor Commented:
The part of EzRoute.exe's role is to synchronize it's data with MS SQL server every morning (I have MS SQLCE installed on pocket PC as EzRoute.exe requires it). I assume that problem is related with SQL because its newer happens before, when database was about 20-25GB in size. Now size of database is 40 GB and I have no other problem related with size. Another thing that makes me think thats it can be solved by doing something with SQL is that after restarting MS SQL server EzRoute.exe synchronizing with no problem about 0.5-1 hour and then problem appears again.

restarting SQL server could be a solution but I have about 50 pockets with EzRoute.exe  running on them and they are not syncing all in same time.
hjgodeTier 3 Senior Technical Support EngineerCommented:
Sounds like you have to look at the servers SQL and SQL CE Agent (SQL Compact) logs. Possibly you have to change the log level of SQL Compact agent.

Possibly the server runs out of memory. Possibly youre question should be moved to the sql server area of experts-exchange.

The code you showed does not show any SQL client or merge command. How do you sync the data? Does it sync 20GB to the device???

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
artakamiAuthor Commented:
No I don't sync 20GB, when size goes up server becomes slower. This happened before and what i have done, I moved database to another server and started clean database on the main server. but I cant do it now because we are in middle of financial year, and using two  separate databases will be disaster.

About SQL CE log and server memory I can tell you tomorrow morning (the company is in GMT+4 +DST)
artakamiAuthor Commented:
Here is another report of same error. It comes from WM6.5 (previous one from WM6.1)

at EzRoute.Synchronize.UpdateProducts()
at EzRoute.Synchronize.btProceed_Click()
at System.Windows.Forms.Control.OnClick()
at System.Windows.Forms.Button.OnClick()
at System.Windows.Forms.ButtonBase.WnProc()
at System.Windows.Forms.Control._InternalWnProc()
at Microsoft.AGL.Forms.EVL.EnterMainLoop()
at System.Windows.Forms.Application.Run()
at EzRoute.MSR.Main()
artakamiAuthor Commented:

Sounds like you have to look at the servers SQL and SQL CE Agent (SQL Compact) logs. Possibly you have to change the log level of SQL Compact agent.
It might sound amateurish, but how to enable SQL CE Agent (SQL Compact) logs on Windows Mobile?

Possibly the server runs out of memory.
Server has 8GB physical memory installed on it. and normally loaded only 5.32-5.50GB sqlserver.exe using 1.5-1.7GB. While Syncing memory usage by sqlserver.exe does not change but processor usage goes up to 7%.
MS SQL Server memory Options setted up:
Minimum Server Memory: 2048MB
Maximum Server Memory: 5120MB
"Use AWE to allocate memory" unchecked.
Can anything be wrong here?
hjgodeTier 3 Senior Technical Support EngineerCommented:
SQL CE agent runs on the server, but as you dont know of it, the EzRoute.Sync command does not use it. SQL server CE agent is used for RDA and Merge Replication.

Look at the SQL server logs.
artakamiAuthor Commented:
I have enabled "AWE to allocate memory", and it seems to be working.
The memory usage now is:
   server's memory usage went up to 7,5GB
   but sqlserver.exe is now using only  110MB
I'll leave it to run a couple of days for testing

hjgode: thanks for the clue.
artakamiAuthor Commented:
No errors after two days testing.


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.