Monday, June 15, 2009

CHM files and Vista

I’m working on installing on a new server, TFS 2008, and in the setup directories there is an Install Guide.  Being the diligent (for once) developer, I opened it up, and it said to download the latest install guide giving me a link. 

However, after downloading the new chm file from Microsoft, it wouldn’t open.  On one system, it said to check my dns server.  and on my host Vista system, it just wouldn’t display.  I opened up IE, checked the local intranet settings and didn’t see anything there.

The solution?  I right-clicked the file, and noticed that there was an Unblock button.  After clicking that, it opened just fine.  Apparently, Vista was preventing me from viewing the web pages inside the help file because they came from a different zone.

 

Once unblocked, the button no longer shows up, and I can read it just fine.

Friday, June 5, 2009

Stored Procedure taking forever.

Today, I came across an issue where from Sql Server Management Studio, a stored procedure was taking forever to run.  But from the application it was running just fine, and if I executed the sql from within the proc on it’s own, it ran just fine. 

Luckily, a friend, Chris Brandsma had stumbled across this about a year ago, and posted it and a solution on Elegant Code.

http://elegantcode.com/2008/05/17/sql-parameter-sniffing-and-what-to-do-about-it/

It’s called SQL Parameter sniffing, and MS (as well as Oracle and the others) use it to improve performance of stored procs.  However, if you have a large or sudden variance in the number of rows returned, the proc will seem to “hang up.”

At least I know what the fix is, and what to look for if it happens again on one of those “random” timeout bugs.

Wednesday, May 20, 2009

VS2008 and SS Express 2008

If you’re running Visual Studio 2008 sp1 and Sql Server 2008 in Vista x64, then you’ve probably come across the error when creating a database:

 

“Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component of download from the URL:

http://go.microsoft.com/fwlink/?LinkId=49251

 

It took me several days with no real solution until I found a reference to http://support.microsoft.com/kb/957944 

Apparently there is a bug with VS2008 and Sql Server Express 2008 in that some of the files aren’t properly registered, so it doesn’t realize that you have a valid sql server install.  And to make matters worse for finding the solution, it only happens if you are using x64 everything. 

 

You’ll have to email Microsoft to get the Hotfix, or install 32bit sql server express.

For me, the Hotfix did work.

Monday, May 18, 2009

nunit and VS2008

I’ve recently started using NUnit on some of my side projects, and the one frustrating thing has been the lack of ability to debug the unit tests. 

I know, I can see the “run” external app on the unit test project to point to the nunit directory, or I can run nunit, manually attach to process, etc.  But those seem kinda hacky.  Or I could shell out money for other solutions.

Well, codeplex has once again saved the day:

 

NUnitit is a project that adds a new tools menu that will allow you to debug VS projects in NUnit without having to set the execute remote, or attach process.  It in will auto detect the NUnit install, so if you have NUnit installed in a different directory, you’ll still be fine.  And you aren’t forced to always use NUnit.  You can set your projects up for MSTest and NUnit and be able to debug both.  I hope it’s

Friday, May 15, 2009

Top 1 in a subquery…

So I came across an interesting sql problem.  I have a list of devices that could have multiple customers attached to the device.  And on the admin page, i need to list the devices and at least one customer attached to the device.

I didn’t want to display multiple rows in the table each with the same device but multiple customers.  This is how I solved it:

select * 



from devices d left outer join customers c on d.id = c.deviceid 



        and c.id = (select top 1 id from customers where deviceid = d.id)




 



The first left outer join, insures that if i have a device with no customers, I’ll still get the device results back.  If I have multiple customers, I’ll get the first one returned.  I could put other “filtering/sorting” in the subquery if i wanted, but this seemed to work enough for my purposes.

Thursday, May 14, 2009

Bugged by FindControl….

 

I’ve always been bugged by the “FindControl” method on the Gridview, or any part of the page (I mainly use it on a gridviewrow after selecting).  So I wrote a little Generic method.  This can be added to a utilties class, or just on the codebehind page itself:

 

   1: public T FindControl<T>(Control searchControl, string controlId) where T : Control {



   2:         return (T)(searchControl.FindControl(controlId));        



   3:     }




To use the new FindControl:





   1: Label foo = FindControl<Label>(gvTest.SelectedRow, "myIDLabel");




This is instead of doing something like:





((gvTest.SelectedRow).FindControl("customerId") as Label).Text




Well, at least it seems cleaner to me in code.  I’m sure that there are better ways, but this works for me for now.

Tuesday, May 12, 2009

Amazing tool for VS 2008 and Sql Server

I was just told by a friend that I need to check out what he called “Data Dude”, which is an add-on for Visual Studio 2008. 

It adds a Database Schema compare so that you can compare two different databases.  I ran it on our beta db and dev db, and found several differences that I didn’t expect. 

Everything from triggers, indexes, columns, etc. 

dd1

It’ll let you drill down into the dependencies, allow you to make the updates, or create new items, etc:

dd2

You can easily see the differences:

dd3

Here’s the Link:

http://www.microsoft.com/downloads/details.aspx?FamilyID=bb3ad767-5f69-4db9-b1c9-8f55759846ed&displaylang=en