This is a simple one. If you use the Publish feature in Visual Studio, you might be wondering how you can tell why a publish fails. The reason could be anything from an image file not being loaded in a project, to something more serious. To find out, you can click on View and then select Output to see exactly why the publish failed. Wasn't that simple?
Smooches,
Kila
This blog is for all Microsoft & .net lovers who may find themselves in need of help or information once in a while. We all have questions and we all need to know more than we know right now. When I come across things that I think may be useful, I post it. When I have something to say that I think is important, which is everything, I post it. All of my C#, ASP.NET, VB, AJAX & programming friends around the world are welcome to the info in my blog - Ramblings Of A Crazy DotNet Woman!
Friday, September 24, 2010
Wednesday, September 22, 2010
How To Uninstall Internet Explorer 9 Beta
I made a mistake. I should have known better than to install a Microsoft Beta product. I love Microsoft, but their Beta products have some real quirks sometimes (I know....hence the term Beta). I usually wait - never wanting to be first in that arena. However, I decided to take a chance on Internet Explorer 9 Beta. The install SEEMED to go smoothly. The computer restarted, but I would get an error when I tried to use IE9. Every single time I clicked on it, I got the dreaded Windows has an error message and then Windows is checking for a solution message. Over and over. I tried all of the instructions provided by Microsoft to fix it, but I finally decided that I didn't and don't have the time to work through the issues. I need IE for development purposes and it HAS to work for me so I did an uninstall. However, when I went to do my uninstall, I couldn't find IE9! Since anything that is added has to have a way to be removed, I started searching to find it. I did and here is the solution so you won't have to spend as much time as I did.
On Windows 7 here is what you do:
On Windows 7 here is what you do:
- Go to Control Panel
- Select Programs And Features
- In the upper left hand corner, select View Installed Updates
- You will be provided with a list of updates, but you will likely not see Windows Internet Explorer 9 clearly in the list
- To find Windows Internet Explorer 9, go to the search box in the upper right hand corner and type in Windows Internet Explorer 9
- Windows Internet Explorer 9 will magically appear and you should select it and then hit the Uninstall button.
- The computer will uninstall the components and then ask you to restart.
- Once you restart, you will need to set up some attributes of Internet Explorer 8 again, but you will be rid of Internet Explorer 9 and ready to rock and roll.
Whew....lets not EVER do that again until IE9 is ready - lol!
Smooches,
Kila
Monday, September 6, 2010
How To Solve A SQL Server Database Marked As Suspect Mode
I'm going to keep this short and to the point. You may log into SQL Server some day and find that some of your databases have an exclamation point along with being marked with the following: DatabaseName (Suspect). That just makes you frown. Well I'm going to show you how to turn your frown upside down!
The solution is listed below.
Smooches,
Kila
SQL Server marks your database as (Suspect). It won't open and you don't know what to do.
Solution:
To solve the problem, run the following in query analyzer.
EXEC sp_resetstatus 'YourDatabaseName';
ALTER DATABASE YourDatabaseName SET EMERGENCY
DBCC checkdb('YourDatabaseName')
ALTER DATABASE YourDatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB ('YourDatabaseName', REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE YourDatabaseName SET MULTI_USER
After you run this, right click on the database and hit Refresh. There you go! Now your frown is turned upside down!
Thursday, September 2, 2010
Primary Keys Do Not or Should Not Equal Clustered Index....Repeat After Me...Learn How To Add A Clustered Index On A Non Primary Key Column
Today I'm going to tell you about a novel concept that I just had to demonstrate to one of my employees who didn't know/believe that it was possible. Before I tell you about this concept, I need to give you a little bit of background information. If you are using SQL Server, you know that when you create a table and add a primary key, a clustered index is automagically created for you on the primary key column. However, the problem with that is that the primary key you create may not be the clustered index you are looking for. There can be only one clustered index on a table. SO what are YOU going to do if the clustered index on your primary key is not on the column you want? What are you going to do if you need to add a clustered index on a column that is not the primary key? The answer to those questions is to change the clustered index first and then create your primary key. In order to change your clustered index, you need to remember a few things.
I love #4.... I love #4....repeat after me....
So with all of those things in mind, let me give you an example. Lets say that you have a table called Options. Your table is defined like this.
CREATE TABLE [dbo].[Options](
[OptionId] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Options_OptionId] DEFAULT (newid()),
[OptionName] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionDisplayName] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionDescription] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionStatus] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Options_OptionStatus] DEFAULT ('ACTIVE'),
[LastStatusChangeDate] [datetime] NOT NULL CONSTRAINT [DF_Options_LastStatusChangeDate] DEFAULT (getdate()),
[CreatedBy] [uniqueidentifier] NOT NULL,
[DisplayOrder] [int] NOT NULL,
[DateAdded] [datetime] NOT NULL CONSTRAINT [DF_Options_DateAdded] DEFAULT (getdate())
) ON [PRIMARY]
Here is what this table looks like in the flesh without a key:

Looks good right? Now what? Well if you are like most people, your next step is to add the primary key! But this isn't correct. Adding the primary key will automatically create a clustered index. INSTEAD, we are going to create the clustered index FIRST! That's right! I said FIRST! You create the clustered index first and then you add the primary key after the fact.
Here is what you end up with.

You didn't see it, but the table is now physically ordered by the Display Order column - NOT the OptionId column. As you can see, we have a Clustered Index AND a Primary Key column which is unique, yet non-clustered. How did we do that? We did it by remembering to do the following:
This will allow you to have the clustered index set on the column that you actually should have it on instead of using the default set up that SQL Server offers you.
Problem:
You don't know how to add a non primary key column as a clustered index in SQL Server.
Solution:
Add the clustered index first on the column the table should be ordered on and then add the primary key.
* Note - Always remember to add your Clustered Index and then save and then add your primary key and then save AND THEN add your relationships. If you are using the SQL Database Diagram feature, don't try to add your clustered index and then use the diagram to add your primary key and relationships without saving the primary key BEFORE YOU ADD RELATIONSHIPS. If you add the clustered index and then go to the diagram to add the primary key and relationships WITHOUT SAVING the primary key before you add the relationships, when you save the primary key and relationships, the system will remove your custom clustered index and try to add the clustered index on the primary key only. This seems to be a quirk of using the database diagram feature.
Always remember the order -
- A primary key is not an index. Primary keys uniquely identify columns in your table - nothing more and nothing less. You don't have to use them for indexing.
- A clustered index, reorders the physical rows of your table. So if you are consistently doing searches on a particular column AND it is unique in your table, you can use that column in a clustered index. Don't forget this. I always use the example of a telephone book. Clustered Indexes are like telephone books. Why would you want to have a telephone book ordered by a randomly generated Primary Key? The answer is that you wouldn't. Instead, you need a real world way to order your information.
- You SHOULD NOT let SQL Server decide the clustered index for you. It happens by default, but accounting for this is part of good database design.
- Setting up a clustered index that IS NOT your primary key is easy to do.
I love #4.... I love #4....repeat after me....
So with all of those things in mind, let me give you an example. Lets say that you have a table called Options. Your table is defined like this.
CREATE TABLE [dbo].[Options](
[OptionId] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Options_OptionId] DEFAULT (newid()),
[OptionName] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionDisplayName] [nvarchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionDescription] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OptionStatus] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT [DF_Options_OptionStatus] DEFAULT ('ACTIVE'),
[LastStatusChangeDate] [datetime] NOT NULL CONSTRAINT [DF_Options_LastStatusChangeDate] DEFAULT (getdate()),
[CreatedBy] [uniqueidentifier] NOT NULL,
[DisplayOrder] [int] NOT NULL,
[DateAdded] [datetime] NOT NULL CONSTRAINT [DF_Options_DateAdded] DEFAULT (getdate())
) ON [PRIMARY]
Here is what this table looks like in the flesh without a key:

Looks good right? Now what? Well if you are like most people, your next step is to add the primary key! But this isn't correct. Adding the primary key will automatically create a clustered index. INSTEAD, we are going to create the clustered index FIRST! That's right! I said FIRST! You create the clustered index first and then you add the primary key after the fact.
Here is what you end up with.

You didn't see it, but the table is now physically ordered by the Display Order column - NOT the OptionId column. As you can see, we have a Clustered Index AND a Primary Key column which is unique, yet non-clustered. How did we do that? We did it by remembering to do the following:
- Create your Clustered Index FIRST - before you add a Primary Key!
- Add your unique Primary Key after you have added the Index.
This will allow you to have the clustered index set on the column that you actually should have it on instead of using the default set up that SQL Server offers you.
Problem:
You don't know how to add a non primary key column as a clustered index in SQL Server.
Solution:
Add the clustered index first on the column the table should be ordered on and then add the primary key.
* Note - Always remember to add your Clustered Index and then save and then add your primary key and then save AND THEN add your relationships. If you are using the SQL Database Diagram feature, don't try to add your clustered index and then use the diagram to add your primary key and relationships without saving the primary key BEFORE YOU ADD RELATIONSHIPS. If you add the clustered index and then go to the diagram to add the primary key and relationships WITHOUT SAVING the primary key before you add the relationships, when you save the primary key and relationships, the system will remove your custom clustered index and try to add the clustered index on the primary key only. This seems to be a quirk of using the database diagram feature.
Always remember the order -
- Add clustered index on your column
- Save
- Add primary key
- Save
- Add relationships
- save
Smooches,
Kila Morton
Saturday, August 28, 2010
How To Do A One To One Mapping In Fluent NHibernate Using HasOne! It Is So Easy! (Lets Map A One To One With Fluent NHibernate..YEAH!!)
I am going to give you a solid example of a One to One Fluent NHibernate mapping. Fluent NHibernate can be a fabulous tool once you learn how to use it. Once you get the hang of it, it is so much simpler than Entity Framework. I know that your eyes may bulge at that statement because what could be easier than dragging and dropping on a GUI. Automapping in Fluent Nhibernate is really even easier than that - ONCE YOU UNDERSTAND HOW TO DO CERTAIN THINGS. One of the ways you can learn more about Fluent NHibernate is by reading the documentation, however, sometimes that is not enough. One of the things that I found when trying to figure out how to do a one to one mapping using .HasOne is that the documentation on using .HasOne is sparse at best. What I found, over and over, was that there were no EASY, reasonable, concrete, full examples of exactly how you should map a one-to-one in Fluent NHibernate using .HasOne. So, I sat down and invested some time in figuring out how to do a one-to-one mapping in Fluent NHibernate using .HasOne and now I'm going to make things easier for you by telling you how to do it without adding all kinds of crazy things to your code and without pulling out your hair.
Since I like to give clear and concise examples, lets go through this step by step. This example is extremely simple, but it illustrates the point beautifully.
We are going to map two tables - TestUser and TestFullName. In this example, every user needs to have a full name saved with them. There can be only one name for each user. The two tables are connected on the UserId so TestUser.UserId = TestFullName.UserId. OK. Lets get all Fluenty (I made that word up)!
Step 1 - The Database Tables
You can create the two tables in any way you deem appropriate. The tables should have the columns specified in the following image:
(CLICK ON THE IMAGE TO SEE A BIG VERSION OF IT)
Notice the one to one key designation. Also, as you can see, each table has UserId as the primary key, which is the key feature of a one to one mapping in Fluent NHibernate. As you can also see, a relationship has been defined on the two tables. That relationship establishes the TestUser table as being the Primary Key table and the TestFullName table as being the Foreign Key table. This is EXTREMELY important in the mapping. If you accidently set the mapping up using reverse syntax, your mapping will not save and you will sit in front of the screen banging on your head asking yourself, "WHY GOD WHY WON'T THIS SAVE?" Now that we have the tables created, the primary keys assigned and the relationship mapped, we are going to go to step 2 and create the classes.
Step 2 - The Classes
public class TestUser
{
public virtual Guid UserId
{ get; set; }
public virtual string Username
{ get; set; }
public virtual TestFullName FullName
{ get; set; }
}
public class TestFullName
{
public virtual Guid UserId
{ get; set; }
public virtual string FullName
{ get; set; }
public virtual TestUser TestUser
{ get; set; }
public virtual void AssignUser(TestUser user)
{
TestUser = user;
user.FullName = this;
}
}
As you can see, I have a property in both tables that references the other table. Notice also that there is no IList mapping in there because this is a true one to one. Do you see how I created a property that allows you to assign a user?
Step 3 - The Actual Mappings
NOW, here is where it gets pretty guys and gals. Why do I say that? Well if you have been looking for how to do a one to one mapping using Fluent NHibernate, you have likely seen example after example of hacks that just don't feel correct due to the convoluted nature of the answers. It isn't as bad as you thought it would be. I am using the AutoMap feature of Fluent NHibernate to do a one to one mapping, so the code below includes the Override keyword. With the AutoMap feature you don't have to worry about class maps - unless of course you want to. Here is the mapping.
.Override
(map => map.Id(f => f.UserId))
.Override
(map => map
.HasOne(x => x.FullName)
.Class()
.Constrained())
.Override
(map => map.Id(f => f.UserId)
.GeneratedBy.Foreign("TestUser"))
.Override
(map => map
.HasOne( x => x.TestUser)
.Class()
.Cascade.All()
))
OOOhhhhhh Yeah! Doesn't that look great? Of course it does. Let me explain a little bit about why I did things this way.
First, you will notice that I map the Id. This is because the Id is not clear to Fluent NHibernate. Since UserId isn't intuitive based on the table names, I had to use the map feature to add an Id. Notice that I also use .GeneratedBy.Foreign. This tells Fluent NHibernate where the Id is coming from. Next, you can see that I've thrown Constrained() in there. That tells NHibernate that there is a Foreign key constraint on TestUser that refers to the primary key in TestFullName. On the other side I use a Cascade since things like Updates, Deletes, etc. should be persisted across both entities. There is one additional very important thing to notice here. I use .HasOne on BOTH sides of the mapping. All of these things ensure that you each instance saved will have the same primary key value across both tables.
I'm not showing you how exactly how to save things because I don't know how you have everything set up, but here is the outline of what you do.
Step 4 - Saving Things
That's it! Aren't I great, super, fantastic and wonderful? Of course I am! This is how to easily map a one to one relationship in Fluent NHibernate using .HasOne. Now remember, don't go getting yourself confused about what a one to one is. James Gregory has spent so much of his time telling people on Stack Overflow and the Fluent NHibernate group that they want a many to one and not a one to one that I'm surprised he isn't in a straight jacket sitting in a padded room somewhere (Maybe He Is...). So read the documentation on Fluent NHibernate and use this example of how to map a one to one in Fluent NHibernate so you can look super smart.
Smooches,
Kila Morton
Problem:
You can't map a one to one in Fluent NHibernate using .HasOne OR you need to know how to do a one to one mapping in Fluent NHibernate.
Solution:
I won't list it here. You have to read everything above on this one!
As a side note, James Gregory is one of the creators of Fluent NHibernate. I think he has likely rubbed the skin off of his fingers due to how many times he has had to explain that many of the mappings that people consider to be one to one are actually many to one. You can take a look at his post here. We have a true one to one Fluent NHibernate mapping here so I don't think that we will get on James Gregory's bad side.
Since I like to give clear and concise examples, lets go through this step by step. This example is extremely simple, but it illustrates the point beautifully.
We are going to map two tables - TestUser and TestFullName. In this example, every user needs to have a full name saved with them. There can be only one name for each user. The two tables are connected on the UserId so TestUser.UserId = TestFullName.UserId. OK. Lets get all Fluenty (I made that word up)!
Step 1 - The Database Tables
You can create the two tables in any way you deem appropriate. The tables should have the columns specified in the following image:
(CLICK ON THE IMAGE TO SEE A BIG VERSION OF IT)
Notice the one to one key designation. Also, as you can see, each table has UserId as the primary key, which is the key feature of a one to one mapping in Fluent NHibernate. As you can also see, a relationship has been defined on the two tables. That relationship establishes the TestUser table as being the Primary Key table and the TestFullName table as being the Foreign Key table. This is EXTREMELY important in the mapping. If you accidently set the mapping up using reverse syntax, your mapping will not save and you will sit in front of the screen banging on your head asking yourself, "WHY GOD WHY WON'T THIS SAVE?" Now that we have the tables created, the primary keys assigned and the relationship mapped, we are going to go to step 2 and create the classes.Step 2 - The Classes
public class TestUser
{
public virtual Guid UserId
{ get; set; }
public virtual string Username
{ get; set; }
public virtual TestFullName FullName
{ get; set; }
}
public class TestFullName
{
public virtual Guid UserId
{ get; set; }
public virtual string FullName
{ get; set; }
public virtual TestUser TestUser
{ get; set; }
public virtual void AssignUser(TestUser user)
{
TestUser = user;
user.FullName = this;
}
}
As you can see, I have a property in both tables that references the other table. Notice also that there is no IList mapping in there because this is a true one to one. Do you see how I created a property that allows you to assign a user?
Step 3 - The Actual Mappings
NOW, here is where it gets pretty guys and gals. Why do I say that? Well if you have been looking for how to do a one to one mapping using Fluent NHibernate, you have likely seen example after example of hacks that just don't feel correct due to the convoluted nature of the answers. It isn't as bad as you thought it would be. I am using the AutoMap feature of Fluent NHibernate to do a one to one mapping, so the code below includes the Override keyword. With the AutoMap feature you don't have to worry about class maps - unless of course you want to. Here is the mapping.
.Override
(map => map.Id(f => f.UserId))
.Override
(map => map
.HasOne(x => x.FullName)
.Class
.Constrained())
.Override
(map => map.Id(f => f.UserId)
.GeneratedBy.Foreign("TestUser"))
.Override
(map => map
.HasOne( x => x.TestUser)
.Class
.Cascade.All()
))
OOOhhhhhh Yeah! Doesn't that look great? Of course it does. Let me explain a little bit about why I did things this way.
First, you will notice that I map the Id. This is because the Id is not clear to Fluent NHibernate. Since UserId isn't intuitive based on the table names, I had to use the map feature to add an Id. Notice that I also use .GeneratedBy.Foreign. This tells Fluent NHibernate where the Id is coming from. Next, you can see that I've thrown Constrained() in there. That tells NHibernate that there is a Foreign key constraint on TestUser that refers to the primary key in TestFullName. On the other side I use a Cascade since things like Updates, Deletes, etc. should be persisted across both entities. There is one additional very important thing to notice here. I use .HasOne on BOTH sides of the mapping. All of these things ensure that you each instance saved will have the same primary key value across both tables.
I'm not showing you how exactly how to save things because I don't know how you have everything set up, but here is the outline of what you do.
Step 4 - Saving Things
- Assign a new user to a name using the handy-dandy .AssignUser method we created in Step 2.
- Save the name.
- Save the user
That's it! Aren't I great, super, fantastic and wonderful? Of course I am! This is how to easily map a one to one relationship in Fluent NHibernate using .HasOne. Now remember, don't go getting yourself confused about what a one to one is. James Gregory has spent so much of his time telling people on Stack Overflow and the Fluent NHibernate group that they want a many to one and not a one to one that I'm surprised he isn't in a straight jacket sitting in a padded room somewhere (Maybe He Is...). So read the documentation on Fluent NHibernate and use this example of how to map a one to one in Fluent NHibernate so you can look super smart.
Smooches,
Kila Morton
Problem:
You can't map a one to one in Fluent NHibernate using .HasOne OR you need to know how to do a one to one mapping in Fluent NHibernate.
Solution:
I won't list it here. You have to read everything above on this one!
As a side note, James Gregory is one of the creators of Fluent NHibernate. I think he has likely rubbed the skin off of his fingers due to how many times he has had to explain that many of the mappings that people consider to be one to one are actually many to one. You can take a look at his post here. We have a true one to one Fluent NHibernate mapping here so I don't think that we will get on James Gregory's bad side.
Tuesday, August 24, 2010
One Solution To The Fluent NHibernate Error "The given key was not present in the dictionary."
Problem:
You have set up some mappings and you get the following Fluent NHibernate error - "The given key was not present in the dictionary."
Solution:
This error can be generated for multiple reasons. One of the reasons is that you forget to map an entity. Before you go any further, check that you have mapped EVERY entity and check that you have registered every entity if you are using something like StructureMap or any other IOC.
Smooches,
Kila
You have set up some mappings and you get the following Fluent NHibernate error - "The given key was not present in the dictionary."
Solution:
This error can be generated for multiple reasons. One of the reasons is that you forget to map an entity. Before you go any further, check that you have mapped EVERY entity and check that you have registered every entity if you are using something like StructureMap or any other IOC.
Smooches,
Kila
Thursday, August 19, 2010
How To Handle The Following Error When Using StructureMap With ASP.NET MVC -The controller for path was not found or does not implement IController.
{"The controller for path 'main_bg.gif' was not found or does not implement IController."} Doesn't that error look great? If you say yes then I know that you don't have enough to do. When you are working with StructureMap, or really any dependency injector, to handle the creation of your controllers, you might run into a situation where you get the following error :
{"The controller for path 'main_bg.gif' was not found or does not implement IController."}
Of course, /Content/images/main_bg.gif won't be in YOUR error message, but some image you are using will likely be in your message. As you can see, StructureMap seems to be looking for a controller for the path of one of my image files. Well isn't that great? Now what? Fear not my friends, the solution to this problem is very, very simple - I promise. Before I tell you the answer, I'm going to ask you a question. What area can you use in MVC to tell your program to ignore or follow certain paths? .........1..........2.........3........Give up? It is the RegisterRoutes area of the global.asax. In this case, you just need to tell your code to ignore the route to your beautiful graphic and StructureMap will stop giving you the error. See, I told you it was simple!
Smooches,
Kila
Problem:
You are receiving the following error when you are debugging your ASP.NET MVC application in Visual Studio.
{"The controller for path 'main_bg.gif' was not found or does not implement IController."}
(You might also see something like the following:
Solution:
Change your global.asax RegisterRoutes routine to ignore the offending path.
Example: routes.IgnoreRoute("{*ignoregifs}", new { ignoregifs = @".*\.gif(/.*)?" }); This will ignore all gifs.
{"The controller for path 'main_bg.gif' was not found or does not implement IController."}
Of course, /Content/images/main_bg.gif won't be in YOUR error message, but some image you are using will likely be in your message. As you can see, StructureMap seems to be looking for a controller for the path of one of my image files. Well isn't that great? Now what? Fear not my friends, the solution to this problem is very, very simple - I promise. Before I tell you the answer, I'm going to ask you a question. What area can you use in MVC to tell your program to ignore or follow certain paths? .........1..........2.........3........Give up? It is the RegisterRoutes area of the global.asax. In this case, you just need to tell your code to ignore the route to your beautiful graphic and StructureMap will stop giving you the error. See, I told you it was simple!
Smooches,
Kila
Problem:
You are receiving the following error when you are debugging your ASP.NET MVC application in Visual Studio.
{"The controller for path 'main_bg.gif' was not found or does not implement IController."}
(You might also see something like the following:
{"The controller for path '/' was not found or does not implement IController."})
Solution:
Change your global.asax RegisterRoutes routine to ignore the offending path.
Example: routes.IgnoreRoute("{*ignoregifs}", new { ignoregifs = @".*\.gif(/.*)?" }); This will ignore all gifs.
If your issue is some other type of file or "/", you simply adjust the regular expression accordingly.
Subscribe to:
Posts (Atom)