Monday, July 10, 2006

As part of DotNetDoc's new "Ask the Doc" format, we are starting our journey by taking a page from the Zen Master himself Scott Hanselman. We will be walking through his list of questions posted in his, "What Great .NET Developers Ought To Know" post. We will not only try to answer the questions but give each a "deep dive" so that we not only can answer the question, but so that we UNDERSTAND the answer. We will go one question at a time until we reach the end. I hope you enjoy, and thanks Scott for the thought provoking questions.

.Net Ought To Know #5 : What is strong-typing versus weak-typing? Which is preferred? Why?

In strongly-typed programming languages you usually have to declare variables prior to using them. Strong-typing is the strict enforcement of [type] rules. All types (int, short, long, string) are know at compile time and are statically bound. So C# is a strongly-typed language because variables must be assigned a type before you use them. If you came from the ASP world then you will remember having to use either Javascript or VBScript. Variables that you declare in either of those languages can hold any data type which makes it weakly-typed.

But lets take this up a level. Instead to talking about programming languages, lets talk about strongly-typed/weakly-typed objects. The DataSet object is a great example. If we use a weakly-typed dataset, the developer needs to know the name of the table and the name of the field being requested. Since we are just passing strings, this code will compile and will not show any possible problems (like typing the name of the table wrong) until run time.

  string s = (string) myDataSet.Tables["Customers"].Rows[0]["CustomerID"];

If our Dataset is Strongly-Typed, we are able to access the names of the tables and columns directly. Any errors are caught at compile time.

  string s = myDataSet.Customers[0].CustomerID;

I am not really going to argue which is better, I will leave that up to you. I will leave you with this question though; would you rather catch your errors at compile time, or run-time?

Happy Programming.

Doc

posted on Monday, July 10, 2006 9:24:56 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1] Trackback
Sunday, July 09, 2006

Setting up membership for your ASP.Net website is pretty simple. All you need to do is:

  1.  run the scripts using the aspnet_regsql.ext tool (C:\WINDOWS\Microsoft.Net\Framework\v2.0.50727\aspnet_regsql.exe    your version number may be diferent) to set up the database tables.
  2. Add a membership section to your web.config. Making sure that you add the <clear/> tag since you need to override the machine.config.

       41     <membership>

       42       <providers>

       43         <clear/>

       44         <add name="AspNetSqlMembershipProvider"

       45                   type="System.Web.Security.SqlMembershipProvider,
                             System.Web, Version=2.0.0.0, Culture=neutral,
                             PublicKeyToken=b03f5f7f11d50a3a
    "

       46                   connectionStringName="LocalSqlServer"

       47                   enablePasswordRetrieval="false"

       48                   enablePasswordReset="true"

       49                   requiresQuestionAndAnswer="true"

       50                   applicationName="/"

       51                   requiresUniqueEmail="false"

       52                   minRequiredPasswordLength="1"

       53                   minRequiredNonalphanumericCharacters="0"

       54                   passwordFormat="Hashed"

       55                   maxInvalidPasswordAttempts="5"

       56                   passwordAttemptWindow="10"

       57                   passwordStrengthRegularExpression="" />

       58       </providers>

       59     </membership>

       60   </system.web>

  3. Add a connection string once again using the <clear/>  tag to clear out the machine.config settings. (I will tell you why soon) 

       16   <connectionStrings>

       17     <clear/>

       18     <add name="LocalSqlServer" connectionString="Data
                 Source=xxx;Initial Catalog=xxx;Persist Security
                 Info=True;User ID=xxxx; password=xxx
    " />

       19   </connectionStrings>


  4. Then load up the Web Site Administration Tool by going to Website\Asp.Net Configuration in VS2005.

  5. You will then be about to configure your membership using SQL2000/2005 using this tool.

So where is the gotcha you might ask?  Well, if you try to name your connection string anything other than LocalSqlServer, when you get to the provider tab you will see a message that says "No Provider Created".  This is why you need to clear out the connection string section using the  <clear/> tag so that you can override the setting in the machine.config.  

 

I hope that helps someone.

Happy Programming

 

Doc


posted on Sunday, July 09, 2006 11:10:27 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
Friday, July 07, 2006

I was just talking to a possible client the other day when the inevitable subject of "Which Technology is the Best" came up. He was a designer but also did a little bit of PHP. The reason he used PHP was because that was what his other Designer friends used.  This of course started up the "Which is better" argument/discussion.

I have always firmly held the stance that :  I JUST DONT CARE. 

C# or VB.Net, which is better?   Who cares?  What is the client paying for? I program in both, and you should too.

ASP/ASP.Net or PHP?  Who Cares,  how many jobs can I get doing PHP sites and how many with ASP/ASP.Net. ( You may have noticed that I did not even go into the enormous difference between PHP and ASP.Net)

The bottom line is, go where you can find work AND do it well!!!  Whatever you do.  

On that note, I found a great blog post that talks about this HERE.  Check it out.

Happy Programming!

DotNetDoc

posted on Saturday, July 08, 2006 1:56:32 AM (GMT Daylight Time, UTC+01:00)  #    Comments [3] Trackback

OK... So one of the blogs I read is from a very technical person who writes a very non-technical blog. Most of the .Net world already knows who his is but if you have been living on another planet, his name is Rory Blyth.

Now his blog can get a little over the top for me sometimes but it is usually hysterically funny.  So I was going through some emails recently and I came across a couple of his posts that I had emailed to someone. The cracked me up all over again.

So I thought I would share them:

The first one is about his experience with T-Mobile and their phone system. Maybe you need to be a customer to find this funny but ..... well maybe not.

http://neopoleon.com/blog/posts/14880.aspx

The second one is more of a cartoon then a blog post. If you have ever worked in a corporate environment, you will definitely get a kick out of this. On the other hand, if you say "I don't get it", then you are management material all the way!!

 http://www.neopoleon.com/blog/posts/434.aspx

Enjoy

DotNetDoc

 

 

posted on Saturday, July 08, 2006 12:08:18 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
Thursday, July 06, 2006

As part of DotNetDoc's new "Ask the Doc" format, we are starting our journey by taking a page from the Zen Master himself Scott Hanselman. We will be walking through his list of questions posted in his, "What Great .NET Developers Ought To Know" post. We will not only try to answer the questions but give each a "deep dive" so that we not only can answer the question, but so that we UNDERSTAND the answer. We will go one question at a time until we reach the end. I hope you enjoy, and thanks Scott for the thought provoking questions.

.Net Ought To Know #4 : What is the difference between an EXE and a DLL?

The main difference between an EXE and a DLL is the fact that an EXE contains instructions for the processor and has an entry point for the execution to start. In this .Net Drag and Drop world where most of the underlying tasks are taken care of for us, this is sometimes hard to see. In the classes I teach, in order to focus on the the code and not the bells and whistles, I often assign Console Applications for homework. The entry point for a console application is the Sub Main() procedure. You can see this by going to project properties and looking at the Startup object. Since a console application will create an EXE, it needs to know where to start execution.

 

 

If we change the Application type from Console Application to Class Library, you will notice that the Startup object type now says <none>. This is because a DLL cannot be executed(or loaded)directly, it can only be called by another process.

 


It is also interesting to note how this question relates to .Net Ought To Know #3. An EXE runs in its own address space(out-of-process) while a DLL will run in the address space of its host (in-process). If you wanted to dive deeper into this, you could load up both a DLL and EXE in ILDasm.exe and look for the <entrypoint> marker in the EXE file.

Happy Programing.

Doc

posted on Thursday, July 06, 2006 4:44:18 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1] Trackback
Monday, July 03, 2006

As part of DotNetDoc's new "Ask the Doc" format, we are starting our journey by taking a page from the Zen Master himself Scott Hanselman. We will be walking through his list of questions posted in his, "What Great .NET Developers Ought To Know" post. We will not only try to answer the questions but give each a "deep dive" so that we not only can answer the question, but so that we UNDERSTAND the answer. We will go one question at a time until we reach the end. I hope you enjoy, and thanks Scott for the thought provoking questions.

.Net Ought To Know #3 : What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?

Well since most people are still not using a 64 bit operating system, we are going to keep this discussion limited to a 32bit OS. In the NT Flavor of operating systems, 4GB of memory is available to each process but it is split 50/50 with with the operating system.

So each process has 2GB of memory available for its private use. The other 2GB is used by the operating system, devices, graphics cards, etc.. Keep in mind, the 4GB/2GB size is regardless of how much RAM you have installed.

This would affect system design if you are creating an application that uses very large data structures or applications like mail servers, database management servers etc.. To address the need for more memory space, you can use a /3GB switch which then splits the memory usage from 50/50 to 75/25. Allowing your application to use 3GB of the 4GB available.

Happy Programming

Doc

posted on Tuesday, July 04, 2006 1:17:21 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
Friday, June 02, 2006

Just an FYI.. I will be apprearing at UCLA on Saturday as part of their Masters Series.  If you are interested, you can check here.

http://ladotnet.org/

DotNetDoc

posted on Friday, June 02, 2006 7:14:30 AM (GMT Daylight Time, UTC+01:00)  #    Comments [2] Trackback
Saturday, May 27, 2006

SQL PROMPT - From Red Gate Software

While I was reading some blogs today I came accross THIS from Scott Mitchell.   SQL Prompt from Red Gate software. It gives you IntelliSense for SQL. Pretty cool stuff. The best part is that it is FREE. Check it out HERE.

Doc

posted on Saturday, May 27, 2006 9:20:01 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
Tuesday, May 23, 2006

I received a question today from one of my readers. (1 of the 10 I guess. LOL ) about VS2005 web projects.

Doc,

    I am trying to add some class code to my website project and it does not seem to want to recognize the namespace that I am using. When I create a namespace in my aspx files I can see them but not in my class files. What am I doing wrong?

This is a common mistake for those who are new to VS2005.  Since you are now able to point to a folder on your drive and bring up a web project without setting up an IIS virtual directory, you need to do things a  bit different. All class files need to be put in a special folder called App_Code. This folder will automatically be compiled at run time. You can use it to store .cs, .vb, xsd, wsdl etc..

The compiler will look to see what extension .cs or .vb your files have and use that languages compiler for C# or VB respectively. The code is then compiled into a single assembly and is made available to the code in your project. This means that you cannot have files of different languages inside this folder.

Or can you...?

By placing a <compilation><codeSubDirectory> set of tags in your web.config. The compiler will create separate assemblies for each folder. Of course, you have to put the files of like type into those folders.

<configuration>
   <system.web>
      <compilation>
         <codeSubDirectories>
           <codeSubDirectory directoryName="/aspnet/code/mySubDir1"/>
           <codeSubDirectory directoryName="/aspnet/code/mySubDir2"/>
           <codeSubDirectory directoryName="/aspnet/code/mySubDir3"/>
         </codeSubDirectories>
      </compilation>
   </system.web>
</configuration>
Hope that helped.
Happy Programming!
Doc
posted on Wednesday, May 24, 2006 1:32:03 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback

Code Monkey @ Code Camp

OK. So most of you know that we put on the "Rock and Roll" Code Camp here in Southern California. The next one is coming up June 24th and 25th in San Diego (http://www.SoCalCodeCamp.org) but the cool thing is that I just got back an email from Jonathan Colton (http://www.jonathancoulton.com) and he is going to make a Code Monkey @ Code Camp version of his shirts that we will giving out at the code camp. Pretty cool stuff. If you have not heard his new code monkey song you have to check it out.  (http://www.jonathancoulton.com/music/thingaweek/CodeMonkey.mp3) You will love it. (It will stop playing about 1/2 way through. You can get the full version on his site for a buck!!  Well worth the price don't you think)

Thanks Jonathan.

posted on Tuesday, May 23, 2006 11:15:04 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback