I ran into a problem when trying to view the Server Explorer window in VS 2008 today. The window would not show up in the Visual Studio IDE no matter what I tried, even when I went to View > Server Explorer. Fortunately, there is an easy fix for this in most cases. All you have to do is open up the VS 2008 Command Prompt and type in devenv /setup. After that close and reopen Visual Studio and you should be able to view the Server Explore window. Warning: This command will reset your VS 2008 menus and toolbars so you could lose customizations you might have made to the IDE.
Microsoft is offering a new program which gives out free .Net Dev Software for independent consultants or companies with less than 10 employees. If you sign up for this program you will get several licenses for VS 2008, Expression Web, SQL Server, Windows Web Server, etc. for 3 years. This is a great new program that should really help startup’s get off the ground and continue to grow the .Net community. Here is the link for more information - http://weblogs.asp.net/scottgu/archive/2009/09/24/announcing-the-websitespark-program.aspx.
We have several MS Reporting Service Reports at my company that were using a parameter that I’ll call “Person”. We display the reports on our ASP.NET Website and when a report is selected that needs the Person parameter we show a Person DropDownList. For some reason this was working fine on several reports, but not for a new report. We verified through the Reporting Service interface and by looking at the actual parameter data in the database that everything looked correct. The Person parameter for the non-working report was identical to the working report. We wasted a lot of time looking for a solution as to why this wasn’t working and eventually figured out that we just needed to reverse the orders of the parameters in the non-working report. For some reason the Person parameter needed to be the last parameter instead of the first parameter. Hopefully this helps if someone else runs into this issue.
I’ve been doing a lot of refactoring lately and I’ve decided to list out a couple of common issues I found with code that I’ve come across in several projects I have worked on.
One of the most common themes I’ve seen in ASP.NET projects is Business logic code in the Click Events. It is really frustrating to see several hundreds of lines in one Event. Please do not put ANY Business logic and especially no Data Access code in there! There are several reasons why, but the biggest reason I have come across is that you really should be setting up Unit Tests in your projects. All unnecessary code in the Click Event makes it much more difficult to write effective Unit Tests as these tests should be testing small pieces of functionality. You end up having to go through and move the code into a Business Layer and and then refactoring code into several small logical methods. You’ll be spending way too much time moving the code around just to create a test. I guess this is the price that is paid when you try to implement tests in a existing project that have none. At least there is one benefit… You’ll get to test out your Unit Tests on all of the code you had to re-architect. ;)
The other issue I keep seeing that I just touched on is methods with hundreds of lines of code. Really, c’mon. Didn’t we all learn in school to refactor our code into smaller methods? It is much easier to find bugs with smaller logical methods. If they are small enough and your method names specifically define their function you should be able to look at the call stack and almost instantly know what went wrong. Throw a exception handler into the small methods and your troubleshooting of the bug becomes that much easier.
Inconsistent Naming Conventions is another thing I’ve noticed. Teams should really decide to a convention and stick to it. But, usually they are just too busy or don’t care enough and you end up with code that has a different style because every Developer that touches the code uses their own style. So, you end up having to go through the code and conforming it to a convention 1 variable at a time. This is can be really frustrating as the variables are usually in 3 or 4 different files and you could be doing this for hundreds of files.
It always comes down to writing good code versus lack of time to do so. We all know what usually wins out, but doing things right the first time just prevents so much work after the fact. But, this is nothing new. It’s the story of Business Software Development.
I needed to do a quick sort on a DropDownList Server Control and found a great way of doing it in just 4 lines of code. Your project will need to be pointed to the .NET 3.5 Framework and will need a reference to System.Linq.
List<string> list = DropDownList.Items.Cast<ListItem>().Select(item => item.Text).ToList();
list.Sort((x, y) => string.Compare(x, y));
DropDownList.DataSource = list;
DropDownList.DataBind();
I found a great resource, MIT Open Courseware, a few weeks ago and I'm writing about it for anyone else that might be interested. M.I.T. is offering several of its previous courses online and is giving anybody who wants to learn the ability to actually see all the resources from the entire semester. They have videocasts, audiocasts, lecture notes, assignments, readings and even the exams (with the answers) available for anyone to look at and use. So far I have been following along with the Algorithms course and love it.
Here is the link to the Computer Science courses they offer -
http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/
Yesterday, I was trying to hook my Asp.Net 2.0 website up to IIS. The problem I was having though is that my Update commands would give me read-only errors. I checked the permissions to make sure the .MDF and the .LOG files had the correct permissions. I then checked to make sure that the read-only checkbox was unchecked and it was for both files. So I googled the problem and tried multiple solutions and nothing fixed the error. Finally, I tried to delete the .LOG file (I had a backup) to see if that would fix the problem and I received an error from not having the .LOG file. So I decided to take the .LOG file out of the Recycle Bin and put it back into the APP_DATA and then ran the solution to see if the Recycle Bin effected any of the permissions and sure enough problem solved. I have no idea how exactly the Recycle Bin fixed the .LOG file, but if anyone has an idea I'm curious to know?
Recently, I added two books to my collection. The two books are Programming Role Playing Games with DirectX and Pro C# 2005 and the .Net 2.0 Framework.
Programming Role Playing Games has really helped out a beginner like me when it comes to programming video games. This book walks you through just about every area of creating a role playing game from writing the story to designing a simple game. As a novice this book has been a great resource for me. The one drawback for me is that this book has been out for a while so it uses DirectX 8 while I am trying to learn how to make games with DirectX 9. At times I have to look up the corresponding code from the book in DirectX 9, but I’m at least learning what that specific chunk of code is doing. So my official review: This book rocks!
Pro C# 2005 and the .Net 2.0 Framework is a great book for experienced .Net programmers. This book is great to use as a reference at work when you are trying to find a way to incorporate generics in to your code or learn about a Namespace like System. Reflection. In no way was this book meant for programmers who are just starting out in C#. Pro C# 2005 and the .Net 2.0 Framework has been the best .Net book I’ve found so far when it comes to content. The author crams about as much as you possibly can of C# in this book. My official review: If you’re a good C# programmer then this book is worth getting!
This inline code is used to insert a dropdownlist into a datagrid/detailsview control in place of a given text area when using the InsertItemTemplate. The reason for doing this is to force the user to submit a answer out of options you choose to give, rather then letting them enter an open ended answer which you might not need or want.
The BoundField is Title.
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
InsertItemTemplate
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='<%# Request.Querystring("testid") %>' DataSourceID="SqlDataSource2" DataTextField="Title" DataValueField="QuizID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:quizConnectionString %>"SelectCommand="SELECT [Title], [QuizID] FROM [Quiz]">
</asp:SqlDataSource>
</InsertItemTemplate>
I came across an error today in SQL Server 2005.
The row value(s) updated or deleted either do not make the row unique or they alter multiple rows.
The reason I got this error was because I created a table for a data mapping application and in my haste I forgot to include a primary key. I checked my table today and found records that were duplicated and whenever I tried to delete or edit a row in SQL Management Studio this error showed up. So I knew I had to put a primary key in the database and in order to do that I had to take care of the duplication. Below are 3 different ways I found to fix this problem.
Solution 1
The first solution is for getting rid of several duplicated rows. This solution used multiple queries.
Step 1.
This query puts the duplicate keys in a separate table that this query creates.
SELECT col1, col2, col3=COUNT(*)
INTO HOLDKEY
FROM Table1
GROUP BY col1, col2
HAVING COUNT(*) > 1
Step 2.
This query creates another new table and just includes unique primary keys.
SELECT DISTINCT Table1.*
INTO HoldUps
FROM Table1, HoldKey
WHERE Table1.col1 = HoldKey.col1
AND Table1.col2 = HoldKey.col2
*Before step 3 check the HoldUps table for duplicates. If you have duplicates in that table refer to the microsoft link below.
Step 3.
This query deletes the duplicate rows from the original table.
DELETE Table1
FROM Table1, HoldKey
WHERE Table1.col1 = HoldKey.col1
AND Table1.col2 = HoldKey.col2
Step 4.
This query inserts the unique rows from the Holdups table into the original table.
INSERT Table1 SELECT * FROM Holdups
Step 5.
Delete the two new tables that the queries created and you’re finished.
Solution 2
This solution is used for instances where you just need to delete one duplicate row. Just use a delete statement like you would any time you delete a row. The only difference is the SET ROWCOUNT 1 makes it so that only 1 row gets deleted. Delete the 1 row and that takes care of the duplication.
SET ROWCOUNT 1
DELETE FROM Table1
WHERE col1 = ‘0001’
Solution 3
This solution is a yet another way to approach this problem. In this approach you use the query below to create a new column that numbers your records 1, 2, 3, etc. This will get rid of the duplication and allow you to delete the records or update them as you need. After you fix the duplication problem, just remember to delete the column.
ALTER TABLE Table1
ADD TempID int IDENTITY(1, 1)
The microsoft link I found that led me to solution 1.
http://support.microsoft.com/default.aspx?scid=kb;en-us;139444
I used a wizard today to create a dataset (.xsd) and when I ran my web application I had hundreds of warnings in my newly generated dataset telling me my code was not CLS-compliant. I checked out what CLS-compliant means and apparently this warning is new in VS 2005 and is used to check to see if your application is following CLS (Common Language Specifications). In other words the CLS are a set of rules used to check if the code in one language can be used in another language.
I checked Google for an answer and only found a work around that turned the functionality of the CLS checking off. I have been looking for another way to go about fixing this problem, but I haven’t found anything yet. There has to be a reason why the dataset generated (by VS 2005) caused all of these errors. Has anyone else gotten CLS warnings and fixed the problem without just turning off CLS checking?
Thanks Jeff for allowing me to join geekswithblogs.net. Since I'm new to the community I should start off by telling everybody a little about myself. I have been developing software professionally for a year and a half now and have a B.S. in Information Systems Management.
I am at a stage in my life that I'm sure many of you have been in at some point in time. I'm a relatively young programmer and want to do just about everything. My attention is diverted between several different pursuits and I'm not quite sure what turn my career will take. Right now I'm focused on trying to get my MCSD, learning how to program games in C#/ C++, dipping into new technologies like Atlas and, oh yeah, that 9-5 that pays the bills.
I look forward to sharing my experiences and endeavors with you as I navigate through the programming world.