Sunday, April 30, 2006

Installation

You know I thought this problem went away with the beta, but it apparently is still there. I had installed Visual Studio 2005 Professional, used it for a while and then tried to install SQL Server 2005 Development Edition. I never get to see the Management Studio. It seems that my computer always wants to use SQL Express.

I can see the Management Studio if I install SQL Server 2005 Development Edition without previously installing Visual Studio 2005 Professional. I haven’t yet tried installing Visual Studio 2005 Professional after installing SQL Server 2005 Development Edition to see if they work together.

Here’s the version of Visual Studio 2005 Professional that I have.

 

Microsoft Visual Studio 2005

Version 8.0.50727.42  (RTM.050727-4200)

Microsoft .NET Framework

Version 2.0.50727

 

Installed Edition: Professional

 

Accessing Data with SQL Express

I have been using Visual Studio 2005 for a while now, but just recently tried accessing a database with SQL Server Express. I had a rude awakening. I couldn’t use the method I had become familiar with. I finally got this to work, but I didn’t find the documentation trail easy. No one ever talks about this; everyone must have figured it out a long time ago, I guess.

Here’s what I tried to do that did not work. I got error messages like cannot login to the database or something cryptic about named pipes. I didn’t pursue the details of the error message. I mean I might have to later, but experience has told me that it is more efficient to figure out how to do something than to analyze why the method you tried did not work. Sometimes it’s frustrating to do that, but the pursuit of knowledge can get in the way of getting the job done. My academic friends are now shaking their heads and wagging their fingers.

I should mention that I can access the data in the database just fine with Server Explorer

Anyway, here’s what I tried to do (that did not work)…

SqlConnection cnn = new SqlConnection();

cnn.ConnectionString = "Data Source=beachparty;" +

   "Initial Catalog=Northwind;" +

   "Integrated Security=SSPI";

SqlCommand cmd  = cnn.CreateCommand();

cmd.CommandType = CommandType.Text;

cmd.CommandText = "SELECT CompanyName FROM Customers " +

    "ORDER BY CompanyName";

cnn.Open();

 

Here’s what I did instead that worked…Is there a better way? I’m sure there is. If you know of one, please don’t keep it a secret!

I chose Data-Add New Data Source… from the Visual Studio menu, I chose Database and clicked Next.

 

Look at that connection string. Not what I expected. Click Next again.

 

I click Next and get asked what I want in my Dataset. I don’t really want a Dataset, so I choose nothing and click finish. The result is that I get a NORTHWNDDataSet.xsd, which I then delete. But what I gained that I wanted was an app.config file, which has the appropriate connection string.

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

<configuration>

    <configSections>

    </configSections>

    <connectionStrings>

        <add name="StepByStep7_7.Properties.Settings.NORTHWNDConnectionString"

            connectionString="Data Source=.\SQLEXPRESS;

               AttachDbFilename=&quot;C:\SQL Server 2000 Sample Databases\NORTHWND.MDF&quot;;

               Integrated Security=True;Connect Timeout=30;User Instance=True"

               providerName="System.Data.SqlClient" />

    </connectionStrings>

 

The point now is how to take advantage of that new connection string stored in the app.config. I noticed that under my project (called AppA) in the Solution Explorer, I see a section called Properties. I can expand that and see a file called Settings.Designer.cs.

 

This file resides in the namespace AppA.Properties, so I put a using AppA.Properties at the top of my winform. I also notice that the file has a property called NORTHWNDConnectionString.

public string NORTHWNDConnectionString {

   get {

      return ((string)(this["NORTHWNDConnectionString"]));

   }

}

 So I replace the connection string assignment

cnn.ConnectionString = "Data Source=beachparty;" +

   "Initial Catalog=Northwind;" +

   "Integrated Security=SSPI";

 

with

Settings mySettings = new Settings();

cnn.ConnectionString = mySettings.NORTHWNDConnectionString;

 

Hmmm… now things are working. All the code above is in the event handler for the button labeled Get Customers.  Click on the button and fill the listbox.

SqlDataReader dr = cmd.ExecuteReader();

while (dr.Read())

{

    lbCustomers.Items.Add(dr.GetString(0));

}

 

4/30/2006 7:46:15 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, April 29, 2006

Agatha is dying. She had two seizures yesterday..the second went on for 15 minutes. She shook and cried and it was heartbreaking. Then we called several vets. Our Hillsboro vet was unhelpful and too far away. Our Seaside vet had an emergency number that went to an answering machine. We called a vet hospital in Astoria and drove her there. We poured cold water on her to keeep her fever down, and she seizured the whole way. She’s there now, getting Valium intravenously. We visited her this afternoon. She looks bad, still twitching and scared. We’ll visit her this morning and ask that she be put to sleep.

She’s the best friend I ever had. I wish so very much that she could go more easily, but I think she suffered these last couple of days. We wanted to give her a chance to live a little longer. Because she had suffered. We had hoped she could have come home and be with us for a few days more. So that we could show her how much we loved her.

Agatha is my dog. We’ve had her for about 15 years, and she’s about 16. We found her back then abandoned in the park across the street.

4/29/2006 1:26:03 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, April 28, 2006

Again an old book … for old people I guess … anyway I’ve read it and still look at it. It’s the Developing XML Web Services and Server Components from Microsoft’s self-paced training kit.

Once again looking at the chapter on serviced components, I came across something I missed last time around. You know, I find this serviced component stuff and all .NET and COM interoperability confusing. I suspect it’s because I came to .NET without first going through COM as most people have.

I think of a serviced component as a .NET component that derives from SystemEnterpriseServices and that can use COM+ services; and that’s why you use them – to use the COM+ services.

Then, the book mentions dynamic registration (the CLR registers the assembly in the COM+ Catalog) and constrasts this with the command line utility regsvs.exe. And then comes this kicker: “On the other hand for COM clients you should register the serviced components manually by using the command line utility, regsvs.exe.” For COM clients? Why would a COM client ever want to use a serviced component? COM clients can get at COM+ services much more directly it seems to me.

I talk to some people about this, but apparently serviced components are not in the path most people around here travel on.

4/28/2006 10:13:22 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, April 24, 2006

This Kalani book … old  … I like it … MCAD/MCSD Training Guide (70-320): Developing XML Web Services and Server Components with Visual C# .NET and the .NET Framework

Chapter 7 is on Serviced Components. Here are some thoughts … take them with a grain of salt.

I think the only reason you want to use a serviced component is to access COM+ services, such as transactions, object pooling, and JIT. The Kalani book has an example (StepByStep7-1) that creates and uses a serviced component but uses none of these features. The example succeeds in showing you how to create and use a serviced component but fails in that there is no motivation for doing so. You keep loooking at the code and saying, Why do this?

The example goes on in StepByStep7-2 to get a strong name for the assembly and in StepByStep7-3 to install it into the COM+ catalog. Then, StepByStep7-4 show how to manage the component with the Component Services Admin Tool. But you know you never actually use this serviced component.

A serviced component doesn’t actually get used until StepByStep7-7. This step shows code that calls a serviced component made in StepByStep7-5, which is just like StepByStep7-1, except that it has a ClassInterface attribute and a custom interface. The serviced component derives form this interface as well as ServicedComponent. But again, the example uses none of the features that would motivate you to using a serviced component in the first place.

4/24/2006 3:11:59 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, April 04, 2006

Our study group has been taking some online tests. We’re going to stop. Scott has already passed the test (70-320); Steve and I will take it this month, and we expect to pass, but frankly at this point we’ve put in so much effort, we don’t care any more.

On one of the tests, we have 171 questions in the database. To test ourselves, we take a 50-question test. What this means is we select 50 questions at random from a database. The questions are then returned to the database and stand the same probability of being selected for the next 50-question test.

I was curious about how many 50-question tests I had to take to be confident that I tried out every one of the 171 questions. I wrote a C# program to calculate that, and the following graph shows my results.

random tests

Just to be safe I took one 171-question test (I got two wrong by the way). I was happy with that score, but I’m not sure how much it means any more. I’ve seen these questions so often by now that I recognize the answer without even having to read through all the question. I force myself to read all the question and reason out an answer, but unfortnately, I’ve memorized the answers by now, and so the test is not measuring knowledge any more.

The peak of the graph is at 15 tests. Here are the values around the peak

12       4280

13       7789

14       11100

15       12650

16       12624

17       11400

18       9449

19       7501

20       5814

21       4307

22       3178

23       2382

24       1653

 

I don’t know what the distribution is. It doesn’t look Gaussian; it’s not symmetric. I think it might be interesting to look at the equations in more detail to determine what distribution models the behavior best. Better, though, would be to look at the algorithm that chooses the questions and see what changes one could make to narrow the distribution. For example, one could weight the probability to preferentially select questions that have not been selected before.

 

4/4/2006 4:55:31 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [5]  |  Trackback