Welcome

You have reached the blog of Keith Elder. Thank you for visiting! Feel free to click the twitter icon to the right and follow me on twitter.

Scripting Database Creation and Fake Data Generation From Data Dude Without Data Dude Installed

Posted by Keith Elder | Posted in .Net | Posted on 30-08-2007

I have Data Dude (aka, Visual Studio for Database Professionals) installed on my local machine.  However, my other team members don’t have Data Dude installed.  They are running Visual Studio Team System for Developers.  This puts us all in a quandary.  For example, if I update the database with Data Dude, how do the other developers get the latest updates installed to their local sandbox?  Better yet, how do they generate fake data for the database when they don’t Data Dude installed?  This is supposed to be addressed in future versions of Data Dude but I needed something now.  Here is what I came up with.

For the record, getting the database updated on other team member’s computer’s is rather easy since Data Dude builds a complete SQL file with all of your changes.  Using sqlcmd from the command prompt you can replay the contents of this file back into your database to reset it.  Initially I created a batch file to do this and here is the results of that:

  • sqlcmd.exe -E -S Localhost -d master -w 500 -I -r 1 -b -m-1 -i “DatabaseSchema.(local).MyDatabase.sql”
  • cd ..\Scripts\Post-Deployment\
  • sqlcmd.exe -E -S Localhost -d master -w 500 -I -r 1 -b -m-1 -i “Script.PostDeployment.sql” -v filepath=”C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA” -v databasename=”MyDatabase”

Running these series of commands from a .bat file re-creates the database just fine.  The problem is I didn’t have a way to generate the fake data for the team members.  While I was writing a unit test for a stored procedure it hit me.  The unit testing tool asked me a series of questions when I created my first unit test.  It asked the database name, if I would like the data regenerated each time and if I wanted to clean the data or not.  Surely it took that information and put it somewhere so it could see what was going on.  I cracked open the app.config file on the unit test project and saw this:

<?xml version=1.0 encoding=utf-8 ?>

<configuration>

 

    <configSections>

        <section name=DatabaseUnitTesting type=Microsoft.VisualStudio.TeamSystem.Data.UnitTesting.Configuration.DatabaseUnitTestingSection, Microsoft.VisualStudio.TeamSystem.Data.UnitTesting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a />

    </configSections>

    <DatabaseUnitTesting>

        <DatabaseDeployment DatabaseProjectFileName=..\..\..\Database\DatabaseSchema\DatabaseSchema.dbproj

            Configuration=Debug />

        <DataGeneration DataGenerationFileName=..\..\..\Database\DatabaseSchema\Data Generation Plans\FakeData.dgen

            ClearDatabase=true />

        <ExecutionContext Provider=System.Data.SqlClient ConnectionString=Data Source=.;Initial Catalog=Mydatabase;Integrated Security=True;Pooling=False />

        <PrivilegedContext Provider=System.Data.SqlClient ConnectionString=Data Source=.;Initial Catalog=Mydatabase;Integrated Security=True;Pooling=False />

    </DatabaseUnitTesting>

</configuration>

 

Digging into this I could see there was a custom section called DatabaseUnitTesting.  I cracked opened the dll Microsoft.VisualStudio.TeamSystem.Data.UnitTesting using Reflector to see what was exposed and how things were configured.  After poking around I created a Windows Console application and added a few references to the project:

 

image

Once the references were setup I added the above app.config to the project and then added essentially two lines.  One to deploy the database and the other to generate the fake data. 

      static void Main(string[] args)

        {

            try

            {

                Console.WriteLine(“Rebuilding Database…..”);

                DatabaseTestClass.TestService.DeployDatabaseProject();

 

                Console.WriteLine(“Generating Fake Data….”);

                DatabaseTestClass.TestService.GenerateData();

 

                Console.WriteLine(“Completed.”);

                Console.ReadLine();

            }

            catch (Exception ex)

            {

                Console.WriteLine(ex.Message);

                Console.ReadLine();

            }

        }

    }

After these few and simple steps I built the project and then ran it.  My console window opened and started running.  After about 30 seconds it finished.

image

Holy cow!  I just recreated Data Dude’s two main features in a matter of a few lines of code!

The only thing left I had to do is to set the VisualStudio DLLs to copy out to the local directory.  This worked on my computer at first since these DLLs were already installed in the GAC.  However, the other team members obviously won’t have them in the GAC.  On each of the VisualStudio DLLs I right clicked on properties and set the “Copy Local” option to true.

image

This will force all the required assemblies to be pushed out into the build folder once a build is done.  The final build ended up looking like this:

image

Now everyone on the team can update their local sandboxes and restore the latest fake data when the database is updated.  I’m really excited to have this working because we’ve had a lot of trouble keeping database changes in sync on developer machines.  Data Dude helps with the problem but only if you have it installed and if you are just a Developer on the team who doesn’t have it installed, there is no reason why you should be left out of all the fun. 

In the future this is “supposed” to be built into Visual Studio so Developers won’t have to jump through this many hoops to leverage Data Dude.  Until then, this works.  I hope those of you that have been struggling with this as I have find this useful.

Data Dude References Wrong Assembly in Unit Test Project With VS2008 Beta 2 Installed

Posted by Keith Elder | Posted in .Net | Posted on 30-08-2007

I just ran into this bug this morning.  I was creating a unit test project for my database so I could create unit tests for the stored procedures.  Turns out when I created the project and added the first unit tests to it it referenced the Visual Studio 2008 Beta 2 9.0 DLL for Microsoft.VisualStudio.TeamSystem.Data and Microsoft.VisualStudio.TeamSystem.Data.UnitTesting. 

The fix was to remove them and then re-add them but why it did this I have no idea.

Finally, Visual Studio 2008 Beta 2 Installed

Posted by Keith Elder | Posted in .Net | Posted on 27-08-2007

image Finally Visual Studio 2008 Beta 2 is installed.  I’ve been through hell trying to get it installed on Vista.  I’ve ran the setup program probably 15 times only to have the .Net framework 3.5 installation stopped. 

I spent countless hours reading blogs, forums and error codes trying to get it installed.  In the end I think the majority of the problem was a bad DVD.  Yes, I am once again haunted by a bad DVD burn from a validated ISO. 

My fix was to first install .Net 3.5 Beta 2 release by itself since this appeared to be the major hurdle most people had problems with during the install.  I figured if I could get the 3.5 framework installed then I *should* be on my way.  After I had this installed I got an I/O error half-way through the web designer tool install.  To remove the I/O and DVD burn problem I mounted the ISO over the network via Virtual CloneDrive and everything installed. 

Once Visual Studio 2008 was installed I had to download the Visual Studio Team Foundation Server 2008 since the previous download did not include the team foundation server client.  To install the client I ran a custom setup and chose the client.  Why this is not integrated with the original install I have no idea. 

I’ll be digging into VS2008 with Smart Clients pretty heavily and look forward to finally running VS2008 outside of a virtual machine.  For those wondering if VS2008 will take over as my daily IDE for development the answer is no, not yet.

Home Theater Setup But Still Missing HD DVR

Posted by Keith Elder | Posted in Man Toys | Posted on 24-08-2007

Everything is finally in and hooked up and working with the new home theater.  The new Samsung TV arrived last Friday along with the new entertainment furniture.   The speakers arrived on Tuesday, one day ahead of schedule.  It took a lot of maneuvering to get everything situated but things are settling in.   Everything is working really well, especially the Onkyo TX-SR705 receiver.  I took a few pictures so you can see how things are shaping up.  

Xbox 360 in 1080P on 56inch Samsung HL-T5687S.  It looks incredible.  Right now I have the component out of the Xbox plugged directly into the back of the TV.  I originally hooked it up to the receiver but never could get the Xbox to run at 1080P.  Not really sure why.  If anyone knows, I’m all ears.

Home Theater 001

Here is a shot standing in the back of the room so you can get a better feel for just how large this screen really is.

Home Theater 003

The only thing still missing is the Comcast HD DVR.  Our area is STILL out of the HD DVR’s with HDMI.  My efforts to hold their children hostage in hopes my HD DVR would be expedited has all been in vein. 

Ever Been Rewarded With Beer at Work?

Posted by Keith Elder | Posted in Funny Stuff | Posted on 21-08-2007

image Some of my fellow team members worked hard on a new request the business gave the team last week.  They executed on it and were rewarded with beer.  How cool is that?  Read the full story here.  And not just any beer but Oberon, my favorite.