Passing a List to a SQL 2008 stored procedure

Background

Ever since I started out working with stuff like Data Access, SQL server, stored procedures and all that sort of gizmo's, I felt a need in certain situations for a stored procedure that is able to take in some kind of array, list, table of items and insert them in a table. This pops out the most in many-to-many relationships between tables. You'd take a .NET object, fill it up with several List<T> properties to hold that sort of info, and then what? Loop over them and open up a set of DB connections for each item? Parse the list into a comma separated string? Or parse it into an xml to process on the server? Sure, they all work, but it's a lot of work every time you need to do it. And between you and me, I'm not too fond of xml processing in SQL Server myself?

Eureka!

So after all those years (well I'm still young, so maybe not all THOSE years) I finally found ONE answer to my problem. Let me repeat the ONE keyword here, because in all honesty, I'm not even sure if this is actually a decent way to get things done. The only thing I guarantee is that it works for me, and kind of makes sense in how it works too (talk about luck!)

How it's done

Part 1: SQL Server

Starting out with the SQL Server part. Keep in mind a tiny scenario where we have a List<Person> object, that we want to insert into a table.

The first thing to do is create a User-Defined Table Type in SQL Server.

image

So first thing to notice is this is actually the same syntax as to create a regular table, except for the keyword TYPE ? AS TABLE. The rest of it is basic column definition. For simplicity reasons, we only keep track of an Id, a surname and a first name.

Next thing to do is to create the table itself. I'll create them with the same column names for the ease of it, but this of course, is not a restriction.

image

And to top it off, I'll add a stored procedure to the party that takes care of the insert logic.

image

So the parameter for this stored procedure is of the User-Defined Table Type Person. This needs to be marked as READONLY, otherwise the procedure won't get created.

Part 2: .NET

Now that the SQL part is out of the way, it's time to start the work in .NET. Let's take a step back and go over what needs to be there. We will definately need:

  • A Person object to hold the properties
  • A List<Person> to hold the people that need to be added to the table
  • Some kind of hocus-pocus to transform a List<T> to a DataTable(System.Data)

Going in a chronological order, we start out with the object itself, which as suspected, is nothing magic.

image

Next on the list is adding some folks to a List<Person>:

image

 

Now, the biggest piece of work in all this would be to parse the List into a DataTable object. Considering the fact that the amount of possible objects is, well, infinite, you shouldn't be translating every single object to a DataTable right? Right. So my solution is to have a DataTable<T> object that holds a List<T>, and translates every property of T into a DataTable object. Nice and easy!

image

And if you remember the List<Person> object that was created a minute ago, called persons, all we need to do now is call the stored procedure to insert those persons in the table:

image

Part 3: the outcome

So when this small project started out, there was this situation at hand:

image

Now when I run this app, we get this:

image

 

Conclusion

There is a little bit of prep work to do with this solution, in configuring the SQL objects etc. But then again, all database designs require prep work, so that's something I'm willing to let slide. But to this day, it's the first easy to implement solution I have to a problem I've been dealing with for over four years now.

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 10/23/2009 at 1:47 PM
Categories: .NET General | C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (5) | Post RSSRSS comment feed

Make me the biggest Windows 7 fan!

Yes I have submitted myself to a desperate contest! So to whoever is reading this, go to http://www.wearewindows7.com/jslq and vote for me as the biggest fan of Windows 7! Thanks!

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 10/5/2009 at 10:10 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (18) | Post RSSRSS comment feed

The big battle: Recursion vs Iteration

 

During my (short) times as a developer, I've come across a few situations where recursive method writing was in order. However, when I look back on a recent conversation I had about recursion, I started wondering why I would ever want to write something recursive. Because it's "clean" code' Because it's cool to say: "hayooo! I wrote something recursive!"? Who knows? One constant factor that is always certain, is that you want to write methods that execute in the most performant way possible. And that is where recursion just won't cut it'

Keeping the old Fibonacci post of a few weeks back in mind, I started investigating versions. The result is a small app that has two methods, one that calulates the x'th number using loops, and one that does the same using recursion.

 

image

image

The result either way:

image

Already from the beginning, the time difference in calculation between the two methods is noticable. Quite obvious, actually.

So now it's time to do some deeper investigation. For this case, I used a trial version of dotTrace to view the application. When the monitoring of the non-recursive method was done, the big part of the trace was as follows:

image

10ms to run the actual calculation of the "Looped" method. Nice! No biggie, all is great. Looks performant. Happy feelings. So what about the recursive method? Two simple lines of code vs a little more work in code? Let's see:

image

Are you kidding me? No of course not. This is kind of expected too, since you always keep on calling methods? And every method call consumes memory, resources... So yeah, big shocker that recursion is not as performant as iteration.

Is that a bad thing? No! Recursion is a great methodology to see things a little different than we normally do. You'll think of the algorithm more than the implementation itself, which to me is a good thing from time to time.

However, if one intends to use recursion in an intensive, deep-leveled method, I'd say think about writing "uglier" code with iterators. It might not save a lot of dev time, but it will probably save you heaps in processing and execution time.

And at the end of the day, execution time is what it's all about, right?

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/24/2009 at 6:24 AM
Categories: .NET General | C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (33) | Post RSSRSS comment feed

Lambdas in daily life

Since this has absolutely NOTHING to do with development or anything related to technology, I?ll keep it short.

I was watching some tv and fooling around with the remote control I came to the shocking conclusion that the remote actually looked like a lambda! SHOCKING :)

The day after that, coming into the office, I noticed that the pump handle of the coffee thermos looked like a lambda as well! See for your selves

IMAGE_408

IMAGE_409

 

So I?m sending out a challenge to the people that read this! Find lambda (or any mathematical symbol) shapes in daily life, take a picture of it and send it to me (jan@dotnetjack.com) with some description of location, scenery etc. I?ll post them up here for everyone to see!

Currently rated 2.0 by 2 people

  • Currently 2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/16/2009 at 1:49 AM
Categories: MathInDailyLife
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (19) | Post RSSRSS comment feed

A wild adventure with Haskell, Fibonacci and .NET 4.0

Last Monday I was starting with a personal little challenge, recommended by Bart De Smet (http://community.bartdesmet.net/blogs/bart/Default.aspx). It was about Haskell, a compact functional programming language Definition from Haskell itself: "Haskell is an advanced purely functional programming language. An open source product of more than twenty years of cutting edge research, it allows rapid development of robust, concise, correct software. With strong support for integration with other languages, built-in concurrency and parallelism, debuggers, profilers, rich libraries and an active community, Haskell makes it easier to produce flexible, maintainable high-quality software."

So thinking about the fact that a "Hello world" thing wouldn't cut it, I thought I might as well make a little Fibonacci calculator toy that takes in the number of the element in the row (eg the 5th element) and return me that value. That part got me to a recursive function like this:

fib :: Integer -> Integer
fib n
    | n == 0  = 0
    | n == 1  = 1
    | n  > 1  = fib (n-1) + fib (n-2)

I then started testing it out. fib 1 = 1; fib 5 = 5; fib 6 = 8; fib 7 = 13 and so on. However, all of a sudden I tried to do a fib 356. BIG MISTAKE!!!! The recursive part of the function didn't really like the whole 356 loops thing :) but this is actually where the fun part started.

I put a playful post up on my facebook saying that counting the 356th element of Fibonacci is hard even for a computer. Nothing more nothing less. Only a few minutes after that, I get the answer from Bart saying that it's: 69362907070206748494476200566565775354902428015845969798000696945226974645

Now THAT is a big number! Now being the alltime challenger that Bart is, he asks me how he managed to get that kind of precise number. Clearly int32 won't cut it in here, and double, long and all that is not sufficient either.

So I open up my Visual Studio environment and start puzzling but don't find the answer right away. At that point Bart was offline again so that bought me some time :) My "quick" solution was to split up the value of the number into smaller integer parts, and then pasting them back together in a string when it needed to be shown. I gave that answer on my facebook and he just simply says: System.Numerics.BigInteger in .NET 4.0

"DAMN YOU!" was my shocked reaction. All that time he was living it up with .NET 4.0 that has a BigInteger class while I was mindcrushing myself to find a solution.

So there are some conclusions to keep in mind from this adventure and post:

1. .NET 4.0 might have some fun new toys to make life easier :)
2. It's mighty fun to be mentally challenged!
3. I hope I impressed the showoff :p (Bart, if you?re reading this? :p)

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/8/2009 at 2:18 AM
Categories: .NET General | C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (45) | Post RSSRSS comment feed

Easily retrieving message body AND context from BizTalk tracking database

I've been searching for a while now on a way to retrieve message body and context from BizTalk without having to use WMI,
simply because I didn't want to write my messages to file, read them back in, parse the context and then delete the generated
files again.
Interesting blog post I stumbled upon was this: View post
But this was not sufficient, because no one managed to get the FULL message context from this method. However, there is a very easy way to do this.
First of all, I defined two strings representing a property name, and a property namespace. They will be the out values for our method.
Now the Context object we get from the tracked message out of the BizTalk Operations dll, implements the Microsoft.BizTalk.Message.Interop.IBaseMessageContext interface. When you look closely at it's methods, you will see a "ReadAt" method. That's the one we need to use.
The Context object also contains a CountProperties variable, which doesn't need any further explanation I think.
So the next part is pretty straight-forward right?
Loop through the CountProperties values, use them as indexes, and call the ReadAt(index, name, namespace) method
for every loop passage, and hold the property value in another string variable.
                string sname = "";
                string snamespace = "";
                for (int i = 0; i < imsg.Context.CountProperties; i++)
                {
                    string value = imsg.Context.ReadAt(i, out sname, out snamespace).ToString();
                    Console.WriteLine(sname + " (" + snamespace + ") = " + value);
                }
And there you have it! Full message context!
Enjoy experimenting with this very cool way of getting body and context of a BizTalk message! IMHO, this is a much better
approach than the WMI way.

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/2/2009 at 3:32 AM
Categories: BizTalk
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (21) | Post RSSRSS comment feed

Automate passing valuable information in WCF headers

This post is about passing through some information at the client to the server, and how to automate this using the WCF configuration.
Case study:
I was with a client, developing WCF services which are hosted on IIS. Since they already have a wide range of security settings stored in databases, it would be a shame to let go of those configurations and force a whole new security model on them instead of trying to integrate their configs into the services.
We have several end users surfing to an intranet site (which is our WCF client), while the site communicates with several servers running WCF services on IIS. The site runs under a simple network service so the Windows Authentication is guaranteed server-side.
But to ensure security for several users (not everyone is allowed to view the same information) we want to pass the current username to the WCF service, and perform a security check with the client configurations, before returning any results.
How do we do this? Well there are probably tons of solutions available, but the way that worked the easiest for me (and my client) is working with custom behaviors on the endpoints, where the username will be passed in a WCF header.
So we need two classes: one to add the header client-side, and one to process the username server-side. In my example, I call them RequestAuth and ProcessAuth. Let's start out with RequestAuth.
Since I want to add something to the message at the endpoint level, I'll need to implement the IClientMessageInspector interface, which is found in the System.ServiceModel.Dispatcher namespace, and the IEndpointBehavior interface, in the System.ServiceModel.Description namespace. BUT, since we are going to add this to a behavior, we need to inherit from the BehaviorExtensionElement class, in the System.ServiceModel.Configuration namespace.
Now before we start implementing, bare in mind that it might come in handy to override the BehaviorType property of BehaviorExtensionElement, as well as the CreateBehavior() method. This is done easily by doing:
    public override Type BehaviorType
    {
            get { return typeof(RequestAuth); }
    }
    protected override object CreateBehavior()
    {
            return new RequestAuth();
    }
Also, to store the current user to send to the server, I'll hold a property UserName:
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string userName;
    public string UserName
    {
            get { return userName; }
            set { userName = value; }
    }
Note: by using the System.Diagnostics.DebuggerBrowsable attribute and setting it to never, no client will ever get to see the private fields in your code. Not only is this safer, but it also gives a better debugger view when debugging.
Now, while it is not necessary anymore in .NET 3.5 to link a property to a private field, this example was written in .NET 2.0, so if you are redoing this in 3.5 you won't need the username field.
On to the implementations then! At first, I have to implement the IClientMessageInspector members.
Keeping in mind that I am SENDING something to the server, I only need to implement the BeforeSendRequest method.
So we need to make a MessageHeader object of string to send the username. After that, I try to retrieve the current logged on user.
In here I needed to make a difference between web applications and desktop applications. But if you are certain that you will ALWAYS
run in one environment (web or desktop) you can drop the check and keep the right username
Now, before I did the actual implementation, I keep a name and a namespace for my header in two private fields, so I can easily find
them back server side.
    [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string hName = "SomeName"; //use your own name for the header in here
        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
        private string hNameSpace = "http://SomeNameSpace"; //use own namespace here
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            MessageHeader<string> header = new MessageHeader<string>();
            header.Actor = "Anyone";
            //Keep the difference between web environments and desktop environments
            if (System.Web.Hosting.HostingEnvironment.IsHosted)
            {
                if (OperationContext.Current != null)
                    UserName = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
                else
                {
                    if(System.Web.HttpContext.Current != null)
                        UserName = System.Web.HttpContext.Current.User.Identity.Name;
                }
            }
            else
                UserName = System.Threading.Thread.CurrentPrincipal.Identity.Name;
            //Add the username to the header
            header.Content = UserName;
            //Creating an untyped header to add to the WCF context
            System.ServiceModel.Channels.MessageHeader unTypedHeader = header.GetUntypedHeader(hName, hNameSpace);
            //Add the header to the current request
            request.Headers.Add(unTypedHeader);
            return null;
        }
So the previous code snippet will add a string containing the username to the WCF request. But to do this for every request, we still
need to add the MessageInspector we just implemented to the behavior. So on to the implementation of the IEndpointBehavior interface!
Well there's nothing much to it in this part, but to use the current clientbehavior and add the inspector:
        public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            clientRuntime.MessageInspectors.Add(this);
        }
NOTE: I use <this> as parameter, because the class we are working in IS a message inspector, thanks to the IClientMessageInspector interface
we implemented.
THAT'S IT FOR THE CLIENT SIDE!!! If you build this in an assembly and sign it, you will be able to add this in your WCF config file.
HOW? Simple: Open your WCF config file with the WCF Config Editor tool (SvcConfig.exe). Under the "Advanced" node, within "Extensions", you have
a node "behavior element extensions". That's where you click New, give your extension a name, and browse to your newly created assembly, and select
the correct behavior element to add (if you have multiple in one assembly). In this case, you need to select the RequestAuth item.
Once this is done, you can navigate to your Endpoint Behaviors, and in your behavior, if you click Add, you will see the new extension in the
list of available extensions. From now on, every service that uses this endpoint behavior will add the new username header to every outgoing request
it makes.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/2/2009 at 3:31 AM
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (36) | Post RSSRSS comment feed

Processing custom WCF header values at server-side

Well since my previous post was about passing information from client to server in a WCF header, this post is about processing
the incoming header to retrieve the original username.
If you read my previous post, I used a class RequestAuth and ProcessAuth. This post will explain the ProcessAuth class.
This time I need to FETCH something from the message, so instead of implementing IClientMessageInspector, I need to implement the IDispatchMessageInspector interface,
together with the IEndpointBehavior interface again, and I need to inherit from BehaviorExtensionElement again, so I can add this
functionality to my endpoint behavior.
In the previous post, I explained that it can be convenient to override BehaviorType and CreateBehavior, so I'll do this again:
        public override Type BehaviorType
        {
            get { return typeof(ProcessAuth); }
        }
        protected override object CreateBehavior()
        {
            return new ProcessAuth();
        }
Also, to store the current user to send to the server, I'll hold a private field userName:
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string userName;
Now, for the IDispatchMessageInspector implementation, it's fairly simple when you think about it. At client-side, I implemented the
BeforeSendRequest of the IClientMessageInspector interface. Now I am at server-side level, so I need to implement AfterReceiveRequest of
the IDispatchMessageInspector interface.
        public object AfterReceiveRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel, System.ServiceModel.InstanceContext instanceContext)
        {
            sUser = request.Headers.GetHeader<string>("SomeName", "http://SomeNameSpace", "Anyone");
            return CheckSecurity();
        }
NOTE: I'm using the same name and namespace for the header as I did at client-side level. This is of course very logically that those two
need to be the same :) otherwise you would never get the right values.
At the end of the method I return CheckSecurity(). This is a boolean method which you can implement at your own needs, it just returns true
or false depending of the access-allowed level of the requesting user.
And that's it for the MessageInspector part! Of course, we also need to add this inspector to every incoming request. This is where theIEndpointBehavior interface comes in again. However, instead of implementing the ApplyClientBehavior method (client-side), we need
to implement the ApplyDispatchBehavior this time, for server-side.
        public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
        {
            endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
        }
THAT'S IT FOR THE SERVER SIDE!!!
Adding this to your server endpoints can be done in the same way I did it in the client configurations.
TO SUMMARIZE: Well, we actually did a lot of work in here with very little code writing. But in my opinion, this shows a nice feature of
customizing WCF.
With this example, you can use your own WCF headers to send some information to the server, and process it there. And not only that, but
you can do this completely automatically by using custom endpoint behaviors.
So that's it concerning my first blogpost :) hope you enjoyed, and feel free to give some feedback!

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/2/2009 at 3:31 AM
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (20) | Post RSSRSS comment feed

Terminating BizTalk instances: WMI vs Operations

The Administration console that is delivered with the installation of BizTalk allows a user to query suspended service instances and resume or terminate them accordingly. However, when you want to go ?outside the box?, and I often do :) you might want to consider finding out possibilities of doing those actions yourself, for instance from a web based managing platform. (note: the following methods work for both BTS2006 and 2009)

When you install BizTalk, there is a WMI provider installed on your machine as well, located in the root/MicrosoftBizTalkServer namespace. That namespace actually provides just about every functionality you need for administration purposes. But in this case, I typically want to focus on the MSBTS_ServiceInstance class. (this is a snapshot taken from server explorer in VS2008)

image

If you right click the class and generate an instance, your current project will get an extra class called ROOT.MicrosoftBizTalkServer.MSBTS_ServiceInstance.cs. When you take a look at that class, you will see the three methods that I?m interested in at this moment: Suspend, Resume, and Terminate. Let?s focus on the Terminate example for this case.

If you want to terminate a service instance through WMI (and there are examples of that over the entire web, so let?s NOT get into that deeply), you can simply use the generated class and say something like:

image

When you provide the InstanceID of your service instance, together with the name and server of the BizTalk Management Database of the BizTalk environment you are working on, the generated class will construct the WMI query for you and execute behind the scenes. So what you need to keep in mind with this method is that you need to go through the entire WMI architecture before actually taking an action.

To me, it sounds easier if I could do the same action in a more direct approach to BizTalk. And lucky for both me as the people who read this (at least I hope people read this :)) we can do that!

When you go to the root install directory of BizTalk (typically that?s C:\Program Files\Microsoft BizTalk Server) you will notice an assembly called Microsoft.BizTalk.Operations.dll, which in this case you can compare to a holy grail :) Let?s take a quick peek at the assembly with Reflector:

image

Of course now every still-awake reader notices the same methods I previously stated. And using these methods are of the same ease as the WMI methods. It goes as follows:

image 

Parameters stay the same. Create an instance of the BizTalkOperations class using the servername and database name of the BizTalk Management Database, and terminate your instance using the InstanceID of the Service Instance object.

Not much difference at first sight, but the thing here really is that when using the BizTalk.Operations, you have a more direct database approach to your action, instead of going through the entire WMI system before actually doing something. Sounds like that could save some performance when you would terminate instances with 500 at a time.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/2/2009 at 3:30 AM
Categories: C# | BizTalk
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (45) | Post RSSRSS comment feed

Making a custom setup dialog using WiX 3.0

Recently I started diving into WiX (Windows Installer XML) as a toolset for a setup project I needed to create. And it didn't take much time to discover that WiX provides some nice out of the box dialogs without having to do much work.
That is, if you only need the basic configurations, such as a folder browse dialog and a license agreement.
However, my project required just that little extra dialog, to provide the location of a SQL database. Basically, what I needed was two textboxes, one to input the server name, and one to input the SQL instance name.

The bad news first: there is not much documentation available (I feel) on how to create some custom dialog stuff.
The good news: it doesn't take much work to do so :) here's how.

You may or may not know that WiX provides some basic layout schema's, from the WiXUI assembly. These are WixUI_Mondo, WixUI_FeatureTree, WixUI_InstallDir, and WixUI_Minimal. In my project, I used WixUI_InstallDir, just for the reason of the need to be able to select a folder to install to.<br /><br />

So what you need to do first is download the source code of WiX. It's an open source project located on SourceForge
Once that's done, locate the file WixUI_InstallDir.wxs in the source folder, add it to your own WiX setup project, and name it MyWixUI_InstallDir (basically, you can choose whatever name you want). Open the MyWixUI_InstallDir file in code window of Visual Studio.

Now, to get what I wanted, I simply added the following code between

<Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

AND

<publish dialog="VerifyReadyDlg" control="Back" event="NewDialog" value="InstallDirDlg" order="1">NOT Installed</publish>

-----

<dialog id="iDTADlg" width="370" height="270" title="Localisation of the BizTalk Tracking database">
        <control id="Next" type="PushButton" x="236" y="243" width="56" height="17" default="yes" text="Next">
          <publish event="NewDialog" value="VerifyReadyDlg">1</publish>
        </control>
        <control id="Back" type="PushButton" x="180" y="243" width="56" height="17" text="Back">
          <publish event="NewDialog" value="iSQLDlg">1</publish>
        </control>
        <control id="Cancel" type="PushButton" x="304" y="243" width="56" height="17" cancel="yes" text="Cancel">
          <publish event="SpawnDialog" value="CancelDlg">1</publish>
        </control>

        <control id="Description" type="Text" x="25" y="23" width="280" height="15" transparent="yes" noprefix="yes" text="Enter SQL Server and Instance to deploy DTA tables to." />
        <control id="Title" type="Text" x="15" y="6" width="200" height="15" transparent="yes" noprefix="yes" text="{\WixUI_Font_Title}Localisation of the DTA database" />
        <control id="BannerBitmap" type="Bitmap" x="0" y="0" width="370" height="44" tabskip="no" text="!(loc.InstallDirDlgBannerBitmap)" />
        <control id="BannerLine" type="Line" x="0" y="44" width="370" height="0" />
        <control id="BottomLine" type="Line" x="0" y="234" width="370" height="0" />

        <control id="DBServer" type="Text" x="20" y="60" width="290" height="13" noprefix="yes" text="Name of the SQL Server to deploy the DTA script" />
        <control id="DBSText" type="Edit" x="20" y="72" width="290" height="18" property="DTAServer" />
        <control id="DBInstance" type="Text" x="20" y="93" width="290" height="13" noprefix="yes" text="Name of the SQL instance to deploy the DTA script" />
        <control id="DBIText" type="Edit" x="20" y="105" width="290" height="18" property="DTAInstance" />

      </dialog>

As you can see, I named this new dialog iDTADlg.
Now to force this dialog to be shown after you chose the install location, you need to find the Publish InstallDirDlg tags and replace the <control event="NewDialog">-line with this:

      <publish dialog="InstallDirDlg" control="Next" event="NewDialog" value="iDTADlg" order="4"><![CDATA[WIXUI_INSTALLDIR_VALID="1"]]></publish>

OK, so that's it for the dialog itself. Now, you normally have a file in your project called Product.wxs. If you want to make use of the WixUI features, you should already have something like this in your file: <uiref id="WixUI_InstallDir" />

Simply replace this with <uiref id="MyWixUI_InstallDir" /> and you're clear :) 

Note: in my iDTADlg I stored some values in properties. These properties were also defined in the Product.wxs file:
    <property id="WIXUI_DTAServer" value="DTAServer"></property>
    <property id="WIXUI_DTAInstance" value="DTAInstance"></property>

So that's it.
So when I run the setup, I get this little basic dialog asking me for a SQL server and an instance:


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: Jan
Posted on: 7/2/2009 at 3:29 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (58) | Post RSSRSS comment feed