IIS Tools - truck load of them at www.iis.net

Today, I had to deliver a talk on Security features in .NET and IIS and I was going through the www.iis.net website.  In the past I had been there for Smooth streaming and other stuff but I stumbled upon the tools, a truck load of them that are very handy utilities while managing a webserver.

  • URL Scan
  • Site Shell
  • Server Defender

and much more related to security at http://www.iis.net/downloads/Security

and with respect to performance http://www.iis.net/downloads/Performance

Ok, and my titbit for this post is that, if you want to use the URL Scan utility on your server running IIS 7, IIS 7.5, you need to enable IIS 6 Metabase Compatibility before configuring the tool. 

Here is a write up on the same site to do that at http://learn.iis.net/page.aspx/125/metabase-compatibility-with-iis-7/

Cheers !!!

Resolving the “TCP error code 10060: A connection attempt failed…” while consuming a web service

Recently, one of the queries I had was on “TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond” while consuming a web service over proxy settings.  Setting the UseDefaultWebProxy to true didn’t help with this error.

I had earlier written a post on explicitly setting the proxy in the configuration file for Web Services.   The scenario here though was, a WCF Service Client trying to consume the web service.

However, the same work around proved helpful.  After setting the proxy explicitly, the web service could be consumed by the WCF Client.

The proxy setting that you want to add to the config file is as below:-

<system.net>
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress="http://address:port"
bypassonlocal="false"
/>
</defaultProxy>
</system.net>

This would go within the <configuration> </configuration> tags.  You can read the post written earlier at http://geekswithblogs.net/ranganh/archive/2005/08/29/51474.aspx 

Cheers !!!

Update to my post on SQL Azure Migration Wizard

Earlier I had written on migrating your Northwind database from SQL Server to SQL Azure.  In that, I had mentioned that the SQL Azure Migration Wizard supports migrating the schema and doesn’t do the data migration which has to be done manually.

Meanwhile, George Huey has published a recent version on the SQL Azure Migration Wizard at CodePlex which also does data migration.  What this means is that, you can take an existing database and generate the scripts and go ahead and deploy the database along with data into your SQL Azure Database.  That’s one hell of work done in a single step, I would say.

What’s more, the recent version also supports the following options

SQL Server to SQL Azure (existing)

SQL Azure to SQL Server

SQL Azure to SQL Azure (multiple accounts)

You can download the latest version from http://sqlazuremw.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32334

Cheers !!!

Moving your ASP.NET Application to Windows Azure – Part II

In the previous post I had described the steps to secure your Windows Azure tokens and get the necessary Visual Studio templates as well as making your web application Azure ready by adding the cloud project and building against it.

Once you have tested the Development Fabric, the instances as well as the application, the next step would be to publish it to the Windows Azure platform.  Select the “CloudService1” project that you added to the solution, right click and select “Publish”

image

Once you click on “Publish”, if you are connected to the internet, it would try and open up Azure login screen and once you sign in, https://windows.azure.com/Cloud/Provisioning/Default.aspx

If you had received the Windows Azure Tokens, and claimed them (as per my previous posts), you would hit the screen as below upon clicking on your project. 

image

in the above, once you click on “New Service” it opens up the page to choose the type of service you would want to create. 

image 

As mentioned earlier, in the CTP you would get to create 2 storage accounts and one hosted service.  In our case, we would require a hosted service, so select the same and proceed to the next screen.  It would provide you the option to specify the Service name and description (note both are mandatory)  I have provided a name as well as description as per the screen below.

image

Clicking on next would take you to the screen where you can choose the sub-domain name.  Provide the name and “Check Availability” and then leave the default and click on “Create”. 

image

The next screen opens up with details of the stuff entered so far, as below:-

image

Click on “Deploy” and it would open up the next screen to upload your configuration files.  When you selected “Publish” in the first step, it would have also opened up your solution’s “Publish” folder automatically.  You can take that path to browse to the CloudService1.cspkg file for the first file upload control and the ServiceConfiguration.cscfg for the second and also provide a label for the deployment.  After that Click “Deploy”

image 

This process would take some time and then get to the following screen.  (If you get an error here, mentioning the role instances are out of range, make sure you changed back the number of roles in your configuration file as mentioned in my previous post to “1” which is default.  The current CTP limits it to 1 instance and although you can change it locally to any number to see the instance simulation in development fabric, when you publish and go to production in the CTP, it doesn't permit more than 1.  So, change the configuration, rebuild and then publish to get the updated configuration files which you can replace)

image

Note that at this stage the application is “Stopped”.  You need to explicitly click on “Run” to start the application.  This would start enabling the Deployment and takes a few minutes based on the server availability and then gets to the “Initializing” stage where the icon (blue) changes to Yellow as well as status to “Initializing”

At this point the custom URL with our sub-domain (in this sample, http://harishweb.cloudapp.net) would not be available since its is still initializing.  Once that is done and it indicates “Ready” as below, you can access the URL to see your app running on the cloud.  You can also “Suspend” and do other things from this screen later.

image

So, with that we have deployed our ASP.NET application to cloud.  If you had followed the Part I and Part II of the SQL Azure migration as well, your application is now running UI Layer on Windows Azure and SQL Layer on SQL Azure.  That makes it a truly cloud based solution.  Here below in a screen shot of my application running on Windows Azure with my custom sub domain i.e. http://harishweb.cloudapp.net (note, I would delete the service shortly and hence this URL wouldnt be available.  since the CTP offers only one hosted service, i would keep it available for me all the time by removing the apps as and when i am done with demo )

image

I hope you found these posts beneficial and do point out if there are errors / omissions in the steps.

Cheers !!!

Moving your ASP.NET Application to Windows Azure – Part I

Earlier I had written 2 posts – Taking your Northwind Database to SQL Azure and binding it to an ASP.NET GridView Part I and Part II .  I thought, I will complete the series with a post on moving your ASP.NET Application as well to Windows Azure making it a truly cloud based application.

Before we start, there are a bunch of things that you would need to do.  First and foremost, you would need a Token for Windows Azure.  You can request for a free token for Windows Azure from here after providing your Live ID and a few more details.   I am not aware of the current time it takes for receiving a token but in the past it used to be 24 hours.

Similarly, if you want to have SQL Azure Tokens, you can get it from here and then login to https://sql.azure.com to redeem the token once you receive the same.  (if you had migrated your SQL Database to SQL Azure as per my earlier posts, you would have done these already)

Once you receive the tokens for Windows Azure, you would need to visit the http://lx.azure.microsoft.com/ and sign in with your Live ID that you used for registering for the tokens.  Once you login, you would be able to see a screen as below

image

Since you haven’t claimed the tokens, there won’t be any projects listed here.  You can click on “Account” tab and click on “Manage my Tokens” in the bottom to claim the tokens for Windows Azure.  With this token you can create 1 hosted services account and 2 blob storage accounts.

And, for development purposes, you would require Visual Studio 2008 SP1 and the Windows Azure Tools for Visual Studio 2008 SP1.  You can download the tools from here

For the rest of the post, I am going to assume that you received the tokens for Windows Azure and SQL Azure and have already migrated the northwind sample database to SQL Azure and did the configuration steps as per Part I and Part II of my posts as well as created the web application with a simple gridview that binds to the SQL Azure database.

Once you login to the portal http://lx.portal.azure.com and click on the Project you will get a screen similar to the one below

image

In the above, you can see that, I already have a blob account by name “harishblobs” that I would use to store heavy data such as video etc., But the point of your interest would be the “New Service” link that is on the top.  You would need this when you are migrating your ASP.NET Application in the steps to follow.

If all is done as per my earlier steps, you have your ASP.NET Application with a simple webform that has a GridView.  The GridView is bound to a SQL DataSource and the SQL DataSource initially was configured to the use the local database instance of northwind database and thereafter, you had changed the connection string pointing it to the SQL Azure database.

The next step is to add a Cloud Project to your ASP.NET Application.  In Visual Studio 2008, click on “File – Add – New Project” and choose “Cloud Service”

image

This would provide a screen to chose the Role type as below

image

Since we already have an existing ASP.NET Application,we just have to click “Ok” with “ASP.NET Web Role” highlighted as you see in the screen.  Make sure the “Cloud Service Solution” is blank as per the above screen.

With this step you will find that a “CloudService1” has been added to the solution and it has a “Roles” folder as well as 2 configuration files. 

Right Click on the Roles and select “Add – Web Role Project in Solution”

image

This would automatically add the existing Web Application in your solution to the Cloud project under “Roles” (you will only see a cloud project icon with the name of your existing web application – the files won’t move)

Once this step is done, you just have to build the whole solution once.  If all is well, and you run the solution, you will get the page but there would be a series of notifications as well as status messages on the Visual Studio bar in the bottom indicating the steps the tool is doing.

After a few minutes you would get an URL which is http://127.x.x.x that has your page.  Remember, we earlier had the localhost URL.  This is the Fabric Controller simulation of your application running on the cloud.  You can click on the notification area in your task bar to open the “Development Fabric UI” (The Development Fabric is something that gets installed when you install the Windows Azure SDK).  You can expand the “Service Deployments” icon in the Development Fabric and then expand the subsequent node to the see the instances running.  By default it shows 0 which indicates one instance of your application is running. You can change is number from the “ServiceConfiguration.cscfg” file in the Cloud Project and set the “Instances Count” to 3 or 4 or whatever you like.  Once you do that and re-run the solution you would get a simulation screen in the Fabric Controller as below

image

Make sure you change back the number of instances to "1" in the file above before publishing to Windows Azure, since in production, as of CTP, it supports only 1 instance. 

With this, we are all set to go the Cloud :)   Considering the length of the post, I would put the next set of steps in another post to follow. Read next post

Cheers !!!

Binding Entity Framework to your SQL Azure Database – Visual Studio 2010 Beta 2

If you have used the Entity Framework that shipped with Visual Studio 2008 SP1, you would really start appreciating the flexibility it offers for building schema driven data access layer and get it to the UI Layer either directly or using a middle tier such as WCF RIA Service.   Check my earlier post on this, if you are interested further :)

Meanwhile, the other exciting stuff that has been around is the SQL Azure which is part of the Windows Azure platform.  SQL Azure provides relational data over the web which means, the Database is hosted, maintained and all is done by us and you get to store your database and query the same as if you were running it in your local Data Center or server.  Of course, SQL Azure is currently CTP and you can get free access to it if you have the Azure Tokens.

While I had earlier written about Migrating your database to SQL Azure that example used an ASP.NET front end which had a GridView doing direct data binding with SQL DataSource.   Obviously, one would want to use some of the more abstract controls such as LINQ DataSource / Entity DataSource.

The trick however, here is that, when you create an Entity DataSource from your local database, the Entity Modelling Designer gets access to pull all the required information and build a nice schema with meta data.  However, if you try to bind your Entity Model to a SQL Azure tool, then you wouldn’t  get this flexibility since SQL Azure doesn’t provide support for the same currently. 

Kevin Hoffman provides a nice work around in his post which I want to repeat here for the sake of continuity in the post.  If you would like to generate an Entity Model out of your SQL Azure Database, have a local copy of the database running with the same schema.  The trick is to first point your Entity Designer tool to your local database and allow it to pull all the required information from here and build the entity model.  Thereafter, you can just visit the SQL Azure Portal at https://sql.azure.com and pick up the identical database’ connection string to be copied to your web.config file to replace the local connection string (Read my earlier post for a steps).

Now, the Entity Framework connection string is a little complicated with a lot of settings.  The connection string path is provided as a property within the main connection string. For example a typical Entity Framework connection string in the web.config file looks as below:-

connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;CONNECTION STRING;Encrypt=True;;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" /></connectionStrings>

In the above, as you can see, the actual connection string starts from provider connection string setting. 

You need to replace that portion with the Connection string copied from the SQL Azure Portal for your Database.  Make sure you don’t mess up with the $quot and other settings by mistake.

Secondly, if you are running Visual Studio 2010 Beta 2 and trying to accomplish this, in the copied connection string, you need to change the User Id part to USERNAME@SERVERNAME (read my previous post on this for more information) .  Also, the default password that is copied from the SQL Azure portal is “mypassword” which you have to change to your actual password.

Finally you also need to set the MultipleActiveResultSets to False since SQL Azure doesn’t support the same currently.  Otherwise, you will get an error.

Once you have taken care of all the steps above, your page works seamlessly as it did while binding the entity framework to your local database (provided you have an identical database to one that is running on SQL Azure)

I have highlighted the important portions in the connection string so that you can take care of those when binding.

Cheers !!!

SQL Azure Connection Error: "Server name cannot be determined. It must appear as the first segment..." - Visual Studio 2010 Beta 2

While working on SQL Azure connectivity from Visual Studio 2010, I faced the above error.  The full error text is as below:-

Server name cannot be determined.  It must appear as the first segment of the server's dns name (servername.database.windows.net).  Some libraries do not send the server name, in which case the server name must be included as part of the user name (username@servername).  In addition, if both formats are used, the server names must match. “

As the message suggested, I tried putting the username@servername but it didn’t help.  The strange this was, the same connection string worked from Visual Studio 2008.  Let me add more clarity to this.

With SQL Azure, you can migrate your on-premise database to SQL Azure (read my previous post on this) and thereafter, just change the connection string in your Web / Desktop Application Configuration file to point to the SQL Azure Database.  The SQL Azure portal provides the connection string in the following format

Server=tcp:SERVERNAME.database.windows.net;Database=DATABASENAME;User ID=USERNAME;Password=myPassword;Trusted_Connection=False;Encrypt=True;

So, in normal cases, you can create an application and do a data binding to get the connection string inserted into the configuration file.  Later, once you migrate the data into the SQL Azure service, you can just change the connection string to the above (after adding the correct Servername, UserId, Password, Database name etc.,)

I did the above steps in Visual Studio 2008 and the application showed zero difference between binding from the local database instance and from the SQL Azure instance.

However, when I was trying this in Visual Studio 2010 Beta 2, the local instance bound properly (as expected) and when I replaced the connection string with the SQL Azure Database connection string, it started throwing the error explained in the beginning of the post.

The change I had to make was, in the connection string, for the User ID I had to specify USERNAME@SERVERNAME example rajiv@sdkldfldfdfd  (both username and servername are imaginary.  note the servername is just the name of the server and not the fully qualified path with .database.windows.net etc., which is not required)

Post this change, the application was able to bind data from the SQL Azure Database without any issues.

So, for Visual Studio 2008, it was simply username and for Visual Studio 2010, it required username@servername

Cheers !!!

FIX for Unable to find “Microsoft.ServiceHosting.ServiceRuntime” Windows Azure Training Kit Nov 09

Ok, I am playing with the Windows Azure Training Kit November 2009 release and the first sample I wanted to try was “Migrating web applications to Windows Azure”.  I believe a whole bunch of people moving to Azure aren’t just going to create new web apps but rather try and move their existing web apps which is why, I thought this exercise is more important.

After following the initial few steps, I came to the place where we manage state providers and one of the requirement is to the StorageClient library available as a part of the training kit.  Now when you add reference to this library (project) and try to build, you may hit the above error i.e. unable to find “Microsoft” or  “Microsoft.ServiceHosting.ServiceRuntime” which is one of the primary assemblies used in the “StorageAccountInfo.cs” file. 

I went through various searches and found out the information that this has moved to Microsoft.WindowsAzure.ServiceRuntime.  What followed was a series of build errors in the same file pointing to various references.  So the idea behind this post is to help folks get through this hurdle.

First off, you heard it already, you need to remove the reference for “Microsoft.ServiceHosting.ServiceRuntime” from both the project references as well as the “using….” statement in the class file.  It needs to be replaced with “Microsoft.WindowsAzure.ServiceRuntime” both in add reference as well as the using area of the class file.

Secondly, you will get the error “RoleManager” does not exist.  This should be replaced with “RoleEnvironment”

Then you would hit the error at “IsRoleManagerRunning”  that needs to be replaced with IsAvailable, i.e. RoleEnvironment.IsAvailable

Then, you would also get error at RoleEnvironment.GetConfigurationSetting.  It needs to be replaced with RoleEnvironment.GetConfigurationSettingValue

Finally, you would also get error at catch(RoleException).  That needs to be replaced with catch(RoleEnvironmentException)

These changes should make your StorageClient project build successfully :)

You will get the above errors in the “AspProviders” project file as well and would need to replace them.

Another error that you would hit is around the RoleManager.WriteToLog which is replaced with the Microsoft.WindowsAzure.Diagnostics for logging events.  You can read more about it at http://msdn.microsoft.com/en-us/library/ee830425.aspx

However, in my case, I commented that particular line and went ahead with the SDK sample.

Would keep posted of more explorations as and when I hit :)

Cheers !!!

Using WCF RIA Services without Silverlight in Visual Studio 2010 for building 3 tier ASP.NET Applications

I have been playing with the WCF RIA Services (erstwhile .NET RIA Services) for sometime and found that most of the samples out there focus on Silverlight based applications.  While the new WCF RIA Services preview for VS 2010 is awesome in terms of its Silverlight integration, I also wanted to test out on building plain vanilla ASP.NET Applications and using the power of WCF RIA Services to build a middle tier for the same.

Ok, to begin with, I already had Visual Studio 2010 Beta 2 installed and went ahead and installed the WCF RIA Services Preview for Visual Studio 2010 Beta 2 (note that, if you already have the WCF RIA Services for Visual Studio 2008 SP1 installed, this doesn’t install on top of it – so you have to chose whether to use the one that works with Visual Studio 2008 with SL3 or VS 2010 Beta 2 with SL4 Beta – i chose the latter)

Once I had these installed, I went ahead and created an “File – New Project – Empty ASP.NET Web Application” in Visual Studio 2010 Beta 2. This creates a blank ASP.NET Web Application.

I went ahead and added an “ADO.NET Entity Data Model” giving it a name “Northwind.edmx” and configured it to use my sample northwind database.   In the Entity Design Wizard, for choosing tables, I chose Products, Categories & Suppliers tables alone and completed the steps to create an Entity model.

This gave an Entity Data Model with 3 tables as well as the auto generated Designer.cs file with Context and Entities.

Now, in normal cases, you have seen a lot of demos where we just add an ASP.NET Webform, drag and drop a grid view control and configure it to use the Entity DataSource template which in turn is configured to use the Entity model created in the above steps.  With a few additional clicks to enable paging, sorting, editing, deleting etc., your complete Grid with CRUD operations would be ready.   We could also do this with SQL DataSource, LINQ DataSource, Object DataSource etc., based on the preference.

The general concern in these approaches were that, there is no actual middle tier and the UI Layer is directly bound to the Data Access Layer.  The moment, you add a middle tier, then the flexibility of binding the Entity Model / LINQ to SQL Model etc., becomes obsolete and one has to configure all the UI => Middle tier => Data Access layer steps manually.

Now, with the power of WCF RIA Services, one can actually generate a middle tier with the underlying Entity Layer.

The next thing I did was to add a “Domain Service Class” (this comes only when you have installed the WCF RIA Services preview for VS 2010) and provide it a name, NorthwindBL.cs.  Note before doing this, you have to build the solution after creating the Entity Framework model so that the entity model is available for the WCF RIA Service template to pick up and generate service methods.

Once I provided the name for the “Domain Service Class” and clicked “Add” it provided the screen for choosing the available Data Contexts and the entities (the tables we chose to create the entity model).  I selected all the three tables (Products, Categories & Suppliers) and checked “Enable Editing” just for the Products Entity.  I also unchecked the “Enable Client Access” checkbox in the top since that is specific to Silverlight scenario and checked the “Generate associated classes for metadata” in the bottom.  This provided a class file with all the CRUD operations for “Products” and Get methods for “Suppliers” and “Categories” Entities.

Note that these methods are completely customizable and provides the platform for adding custom business logic, which was always missing earlier while binding the UI Layer directly using SQL DataSource, LINQ DataSource etc., For example, one of the generated Get method for Products is as below

public IQueryable<Product> GetProducts()
        {
            return this.ObjectContext.Products;
        }

I wanted to make a simple customization to it by filtering out the product list with a where condition.  I could use a LINQ Query and modify the above method as following:-

public IQueryable<Product> GetProducts()
        {
            return this.ObjectContext.Products.Where(p=>p.ReorderLevel>10);
        }

while this is not the greatest business condition, you can get an idea on the amount of customization I could do even for simple crude operation.  In addition, I can also add custom methods to this class file.

The next step is to start building the UI Layer.  I added a simple Webform to the project and added a GridView from design view.  For now on, there are a few tweaking steps that needs to be followed to be able to use the WCF RIA Services.

Once you install the WCF RIA Services, you will get a bunch of assemblies in the locaiton C:\Program Files\Microsoft SDKs\RIA Services\v1.0\Libraries\Server  Out of these, you would require the System.Web.DomainServices.WebControls.dll file to be able to use the DomainDataSource control in the Webform.

Add a reference to it in the project as well as try adding the same to the Toolbox by rightclick on Toolbox, Choose Items and browsing to the above folder.  Once you do that, you can drag and drop a DomainDataSource to the webform.  It automatically adds the Register Tag Prefix as well.

Once this step is done, you can either go to design view and choose the GridView’s configuration set up and choose DomainDataSource under DataSource configuration.  That’s all works as of now.  It doesn’t take further to the available methods, etc., as it would be case with EntityDataSource, SQL DataSource etc.,

Then, you can manually modify the DomainDataSource to add further properties, as below:-

<cc1:DomainDataSource ID="DomainDataSource1" runat="server" DomainServiceTypeName="<ProjectName>.NorthwindBL"
       EnableInsert="true"  EnableUpdate="true" EnableDelete="true" SelectMethod="GetProducts" StoreOriginalValuesInViewState="true"></cc1:DomainDataSource>

For the GridView, a few properties needs to be enabled and with that and selecting a template, the code for GridView looks, as below:-

<asp:GridView ID="GridView1" runat="server" DataSourceID="DomainDataSource1"
            CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True"
            AllowSorting="True" AutoGenerateEditButton="True"
            AutoGenerateDeleteButton="True">
            <AlternatingRowStyle BackColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#EFF3FB" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#F5F7FB" />
            <SortedAscendingHeaderStyle BackColor="#6D95E1" />
            <SortedDescendingCellStyle BackColor="#E9EBEF" />
            <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>

With that, we are good to run the page.  Note that, the page retrieves records and binds on the gridview only for values where reorderlevel is greater than 10 as per the cutomization we made to the GetProducts method in the Businesslayer.

Similarly, the Edit, Update operations work automatically but you can go to the respective methods in NorthwindBL and add a few conditions, checks as and where required.  You can also add Authorization to make sure that only those folks are allowed to modify etc., but I am not covering them as a part of this post.

So, with minimal steps, we could build a three tiered application skeleton and this can be enhanced greatly to build a full fledged app without you having to manually write out the Service Layer methods.

I have uploaded the sample solution along with this post and you can download the same from the link below.  Note that you would need to add your connection string to the Web.config file.

I will try and cover the other scenarios as well in future posts, but for now, we have a 3 tier application built effortlessly with the power of ASP.NET, WCF RIA Services and Entity Framework.

Cheers !!!

SQL Azure Connection error “Cannot connect to <servername>" Client with IP Address is not allowed to access server: Error 40615

If you have been using the SQL Azure Portal for creating SQL Databases and connecting to them from your SQL Server Management Studio, you would have realized the ability to query the Azure Cloud Databases from within the management studio.  While this provides great opportunities in terms of relation capabilities and accessibility over the Cloud, there has been a recent upgrade to SQL Azure and in that process there has been a Firewall Support added to the SQL Azure Portal access.

Specifically when you try to connect to SQL Azure, you would face the error

Cannot connect to <sql azure server name>

Additional Information

Cannot open server <servername> requested by the login.  Client with IP Address "<your IP Address>” is not allowed to access the host server.

Login failed for user ‘<username>’. (Microsoft SQL Server, Error: 40615)

As the error message indicates, the SQL Azure Portal has declined access to the portal for your IP Address.  This specific filtering helps companies protect their data hosted in the cloud from access by just any host.  This allows companies to restrict the access to a specific set of hosts such that they do know that those are safe.

As a result, your existing applications / querying from SQL Server Management Studio might just fail.   Note that by default no IP’s are allowed to access your server.

Also, there has been a change in the way the server is accessed as well as the credentials specified.  Lets see them step by step.

Steps to enable IP Access in the SQL Azure Portal

Visit the SQL Azure Portal at https://sql.azure.com and sign-in with the LiveID that you used to create the SQL Azure database(s)

Click on the Project name to open the Server Administration Page

You will find the Server Name, Administrator username and Server Location details specified.  You would require these when connecting to the SQL Azure database from your Management Studio.  Note that the server name is no longer <servername>.ctp.database.windows.net and just simply <servername>.database.windows.net

You would also find the databases listed under the Databases tab and additionally you would find the “Firewall Settings” tab.  Click on the “Firewall Settings” tab you will find a screen as below:-

image

Check the “Allow Microsoft Services access to the server” check box.  The page posts and then adds a “MicrosoftServices” Record Name as below

image

Click on the “Edit Record” to open up “Custom Firewall Settings” window that lists your IP address as well.  You can also specify a range in case you want to.  Once you have typed the IP Address, click “Submit”  (Note that if you dont have an IP Address range, you would have to type your actual IP Address in the bottom textbox after the “to” which means the top one is 0.0.0.0 to <IP Address you specified>.

You can add more IP Addresses by clicking on “Add Record” button and repeating the above steps. Once you do this, you would be able to access the SQL Azure database from SQL Server Management Studio.

Steps to access the SQL Azure Database using Management Studio

I had already written on this, in my earlier post  that you can check.  But, in the interest of folks who have patiently read this post from the beginning, I am repeating the steps below

Open SQL Server Management Studio

Dismiss the default login window that comes up (a temporary work around)

Click on “New Query” and type the credentials.  The servername is “<servername>.database.windows.net” and the Login is simply <username> and not username@servername as in the past.  Click on “Options” to specify the Database that you created in SQL Azure.  Otherwise, the default would connect to Master.  Once you enter the password in the “Login” tab and click “Connect” you should be able to connect to the SQL Azure database.

If you get any error, check if you had dismissed the initial login prompt and clicked on “New Query” in the Management Studio.

Cheers !!!

Visual Studio 2010 Beta 2 – a first look at the UI and Web Development

Visual Studio 2010 Beta 2 is out and has a slick new UI.  Also, this Beta has most of the features that would ship with the final version compared to the earlier Beta.  Note that while new features might be added, there are chances that some of the features demonstrated here may also not be a part of the final release.  But, for now, lets examine the current Beta 2.  The first thing you would notice and probably like, is the UI enhancements.  Herebelow, is the launch screen.

image

Also, the start page has been modified to accommodate more useful things.  The good thing is that you can completely customize the Start Page since it is a XAML based UI.  You can find the start page itself as a Project at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\StartPages once you install the Beta.  You can change it to reflect your organization specific templates, document repositories etc.,  Optionally you can even turn it off permanently, or, upon opening a project, using the checkbox options in the bottom left.

image

Now, with respect to web development, there are tons of enhancements.  In fact many of the actual web enhancements are figuring in this Beta release and exploring them would require individual blog posts that I would be writing in future.  For a complete list of feature walkthroughs, please visit the MSDN website http://msdn.microsoft.com/en-us/vstudio/dd441784.aspx (and by the way you would realize that the MSDN Website has been re-launched as well with the new UI for easier navigation)

The first thing I did was to explore the “File – New – Project – ASP.NET Web Application” template and create a new web project.  This provides a web template with a default Home Page and About Us page that you can use as-is / customize and get started with a skeleton layout immediately.  The default UI without any work, when run, looks as below:-

image

Other thing to notice is that, by default jQuery 1.3.2 library is included in the Scripts folder, not to mention, the intellisense support for jQuery that has been there right from VS 2008 SP1.  There you had to manually install the docs as well as the jQuery library.  Now, it all comes automatically.

Web.Config file Simplified

Over the years, with ASP.NET AJAX, Data Source provider, IIS 7 configuration, the Web.Config grew extremely unmanageable and working with that would require real patience.  In this release, the Web.Config file has been minified or simplified that it just contains 4 – 5 lines of configuration.  Note that, this is when you select “Empty ASP.NET Web Application” template.  The default “ASP.NET Web Application” template still has entries corresponding to Membership, Roles, Authentication etc., since this is basically a fully functional website with users, roles as well as membership database with default entries (remember “Website Administration” screen in the ASP.NET 2.0 days)

There are much more web related features that I will be covering in the future posts, but for a high level overview, check http://msdn.microsoft.com/en-us/library/ee532866(VS.100).aspx and http://www.asp.net/learn/whitepapers/aspnet40/ 

You can download Visual Studio 2010 Beta 2 from http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx or if you are an MSDN Subscriber from the MSDN Download Center.

Cheers !!!

FileUpload in UpdatePanel, ASP.NET, like Gmail

Earlier, I had written this post on how you can accomplish using FileUpload control in UpdatePanel since by default it wasn’t supported.  The post seems to have helped many and keeps being the most visited one.  However, with the new release of Ajax Control Toolkit (v 3.0.30930) released specifically for .NET 3.5 SP1 (with Visual Studio 2008 SP1), there are couple of new controls.  One of them is the AsyncFileUpload control.

Thanks to the codeplex community which keeps getting better and better with time, the Ajax Control Toolkit has grown into one of our largest community contributed controls for ASP.NET with about 43 controls that help in accomplishing rich user experiences in ASP.NET Websites.

The AsyncFileUpload is one simple way of accomplishing what I had written earlier using PostbackTrigger, the regular FileUpload control etc.,  To be able to use the AsyncFileUpload Control, you must have the latest version of AjaxControlToolkit installed.  The other pre-requisites are obviously NET 3.5 SP1 and Visual Studio 2008 SP1 (or the free Visual Web Developer Express Edition)

You can download the pre-requisites from the respective links above.  For downloading the AjaxControlToolkit, visit the CodePlex site.  You can download just the binary files or the Source files as well, if you require to modify.  The Script Files is useful if you want to just work with the client side scripts and not use the server controls.

Once you have downloaded, you would need to add them to Visual Studio or VWD.

1. Open Visual Studio and create a new webapplication or website.  Click to open the ToolBox

2. Right Click and select “Add Tab”

3. Provide a name say “Ajax Control Toolkit”

4. Right Click the newly created tab and select “Choose Items”

5. Click on the “Browse” button in the file dialog that opens and browse to the place where you downloaded the AjaxControlToolkit binaries

6. Typically I would put them under C:\Program Files\Microsoft ASP.NET for consistency.

7. Select the AjaxControlToolkit.dll and it would list all the new controls.

8. Click “Ok” to add all the controls.

9. You should now see under the newly created toolbox tab these controls.

Once you are done with above, create a simple Default.aspx page in the application you created and drop the Script Manager control into your webform.  Next add an UpdatePanel with ContentTemplate.  Inside the ContentTemplate, add the AsyncFileUpload control into the webform as well as a button and 2 labels for the uploading and displaying messages respectively.  The markup looks something like below

<form id="form1" runat="server">
   <div>
       <asp:ScriptManager ID="ScriptManager1" runat="server">
       </asp:ScriptManager>
       <asp:Image ID="img1" runat="server" ImageUrl="~/Images/spin2.png" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
           <ContentTemplate>
               <cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" UploaderStyle="Modern" ThrobberID="img1"  />
       <br />
       <asp:Button ID="btnUpload" runat="server" Text="Upload"
           onclick="btnUpload_Click"   />
           <br />
           <asp:Label ID="Label1" runat="server" /> 
           <br />
           <br />
         </ContentTemplate>
       </asp:UpdatePanel>
       <br />
       <asp:Label ID="Label2" runat="server" />
   </div>
   </form>

Also, you can see that I have added an asp:Image pointing to a spin image that is specified as the ID for ThrobberID in the AsyncFileUpload definition.  This is optional but nice to have since this would display the throbber icon while uploading takes time.

Once you are done, you would need to define the action in the codebehind or in the script

protected void Page_Load(object sender, EventArgs e)
      {
          Label2.Text = DateTime.Now.ToString();
      }

      protected void btnUpload_Click(object sender, EventArgs e)
      {
          AsyncFileUpload1.SaveAs(Server.MapPath((AsyncFileUpload1.FileName)));
          Label1.Text = "You uploaded " + AsyncFileUpload1.FileName;
      }

Notice, the Label in the Page_Load event is just to indicate that indeed the operation happened asynchronously since the time that is displayed initially doesn’t change once you click on Upload button. 

Try running this and you will find that the whole operation happens asynchronously without a full page reload.  Note that, you would need to still put the AsyncFileUpload control inside UpdatPanel for this behaviour.  Otherwise, it would behave like a regular postback control.

You can download the sample code from

Cheers !!

Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part II

If you like to migrate your Web tier or the ASP.NET Application to Windows Azure, check my new posts Part I and Part II

In the previous post we had examined on getting access to SQL Azure, creating your first database, accessing it with SQL Server Management Studio and then migrating the Northwind database schema to SQL Azure using the SQL Azure Migration Wizard Beta.

UPDATE: The latest version of SQL Azure Migration Wizard migrates both Data and Schema.  You can download the same from http://sqlazuremw.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32334

As explained earlier, the SQL Azure Migration Wizard migrates the schema of your database after tuning it for working with SQL Azure.  However, we would still need to migrate the Data to our SQL Azure Server.  At the moment, the step I took was to open the instnwnd.sql script in SQL Server Management Studio (SSMO) and copy the Insert statements alone to execute.  Note that, you cannot run all the scripts directly onto the SQL Azure portal like I explained earlier due to the limitations / formats supported currently in SQL Azure. 

To begin with, open “C:\SQL Server 2000 Sample Databases” folder (the default location where Northwind and pubs sample database gets installed) and double click on the instnwnd.sql script.  It opens up in SSMO.   Examine the scripts and navigate to the portion where the INSERT statements begin.  I took the portion and put it up as a single insert script.  You can download the script  from the link below:-

 

Running the scripts from SQL Server Management Studio

As explained in my previous post, open SSMO and cancel the initial login prompt.  Click on “New Query” and specify the server name as the fully qualified Azure Server name i.e. <YOURSERVERNAME>.ctp.database.windows.net, specify the user name, password.  Click on “Options” and specify “Northwind” at “Connect to database” option.  Click “Connect”.  It should be able to connect provided you have specified the path, username, password etc., correctly and created the “Northwind” database as per the previous post.  There will be a small error prompt that comes before opening the Query window, as below.  You can ignore that and click “ok”

 

image

 

Once you are in the SqlQuery1.sql screen you can check if the database is created and the tables are there by running  a bunch of few queries as below:-

SELECT * FROM Products

SELECT * FROM Orders etc.,

You will get blank result sets since we haven't migrated the data yet.

Double lick to open the insertnwnddata.sql script downloaded in the first step.  It would open in a new sql window.  Copy paste the script into the first window we got once we connected to the Azure Database.  If you get a connection error.  Try reconnecting using the “New Query” option as explained above.  If all is good, you should be able to execute the scripts.  Once the scripts are successful, you can test if the data is migrated, by again running the SELECT statements above.  They should now list data.   If there is an error, try running the individual INSERT statements for each table to verify which table has the issue.

Once this is done, we are all set to bind this data to our ASP.NET Page.

Binding the SQL Azure database to ASP.NET Page

Open Visual Studio 2008 and create a web application project.  In the Default.aspx page, drag and drop a GridView control and use the GridView’s wizard to connect to your local Northwind database.  Pick the Products table and chose the columns you want to display and complete the steps.  You may want to enable paging to avoid all data shown in the same page.

The above steps should add a GridView, a SQL Data Source to the page.  Once you run the website, it should display the Products table record with the columns you chose to display.  So far, we have bound the local database.  We however, intended to bind it to SQL Azure database that we have created.

Binding the GridView to the SQL Azure Database Table

If you thought this is another big process, you might be in for a surprise.  Visit the SQL Azure portal (https://sql.azure.com) sign-in with your credentials that you used to create the token/database etc., Click on the “Manage” link that comes in the right of the Configuration Page that you get once you sign-in.  The next screen lists all the databases created.  Click on the “Northwind” database radio button to select it.   Click on “Connection Strings” in the bottom (the one in the top gives the connection string for master, so click on the “Connection Strings” button below the grid that displays the databases.   You should get a popup with 3 different connection strings targeting different data access methodologies.  Chose the first one (Click on “Copy to Clipboard”) corresponding to the entry for ADO.NET (the first one). 

In Visual Studio, open the web.config file of the site that we created earlier and visit the connectionstrings setting.  If you had followed the wizard steps, it would have entered a connection string over here, that corresponds to your local database server.

Replace the connection string with the one copied here.  Note, you need to update the password that you used instead of “mypassword”.  Also, remove the trailing semicolon at the end after password. 

If you have done all the steps properly, you should be able to run the solution now and without any other change, the data that is bound to your grid view should display the same as it did when you initially bound it to the local database.  You can try paging / sorting etc., to see if all works fine. 

So, practically, we just had to change the connection string to be able to access the database on the SQL Azure Server.  From a developer’s perspective, the data access technique, binding, control and configuration remains unchanged.

That’s it for this series.  There are quite a lot of steps that I had listed over the last 2 posts.  You may want to check every point if you are facing any issue at any stage.

Cheers !!!

Taking your Northwind Database to SQL Azure and binding it to an ASP.NET Grid View – Part I

If you like to migrate your Web tier or the ASP.NET Application to Windows Azure, check my new posts Part I and Part II

SQL Azure is the latest buzz around Cloud Computing and the ability to take relational database to the cloud as is, is something most would welcome compared to the earlier model of ACE (Authority, Container, Entity) that was there when SQL Azure was SSDS.   Well, like others, I also got interested and wanted to explore the SQL Azure.  SQL Azure is currently in CTP and offers token based access.  I would briefly outline the steps here on getting the SQL Azure Token, although Jim O’Neil has a nice post on this

Visit SQL Azure Registration at Microsoft Connect

Sign in with your Live ID (Passport, Hotmail, MSN, Live)

Fill in the details and submit the form

You should receive the invitation code in an email from an alias “SQL Azure Talk” or something similar (note this may take from a day to a week until the CTP is available)

Visit https://sql.azure.com

Fill in the Invitation Code received in the email

You will be directed a page similar to below

image

Click on the “Manage” link in the right. It will take you to a page as below:-

This page is where you can create / delete databases as well as get the connection string etc.,

image

In the top of this page you will also see “Connection Strings” , “Reset Password” icons and also the Server Name, User Name that you chose, and the location where the database is hosted.

You can click on “Create Database” to specify a new Database table name (that’s all you can do, you cannot create tables from here, just the database)

As you can see, I have created a few databases except master which is the default database.  You can chose an individual database and then click on the “Connection Strings” icon in the bottom (currently disabled) to get the specific connection string for the database you created.

Now, this is the first step towards getting access to SQL Azure Services.

Next, the big question you might have is how do I create tables, procedures etc.,  The MSDN Sample documentation provides you the instructions on creating a basic database with a single table.  However, you might want to create / import a relational database such as Northwind with more tables etc.,  The trick here is that not all data formats are supported, particularly the deprecated ones such as ntext, image etc., at least at the moment and you can’t just go ahead and run the DB Scripts against SQL Azure to create the database and tables.  Lets examine one by one on the steps to access SQL Azure Tables in SQL Server Management Studio, Getting a script that can be executed on SQL Azure, Uploading data to SQL Azure and finally binding it to GridView

Accessing SQL Azure Tables in SQL Server Management Studio

SQL Server Management Studio (SSMO) is probably the most favourite tool used for querying, running scripts etc.,  You can download SSMO for SQL Server 2008 or the free SQL Server Express edition from here

Once you installed, it would prompt you with a login dialog with server details etc., (if you have used it already, you would be familiar with it).  Now, the trick is, to be able to use SSMO with SQL Azure, you need to dismiss the initial login screen and click on “New Query” icon in the top left and specify the server name which is typically like <YOURSERVERNAME>.ctp.database.windows.net (you can find the server name in the screens explained above).  Then specify the username, password and click on “Options” to specify the database that you created above.  Click “Connect” and you should be able to connect to the SQL Azure Server database.  A more detailed step by step instruction is available at Ramaprasanna’s Blog

The above trick of dimissing the initial login screen and again bring it up to enter the azure database credentials is no longer required with SQL Server 2008 R2 November CTP

If you had created the sample database by following the MSDN Sample documentation you can specify that database while connecting (explained in the step above) and then query the tables (select * from T1) to get the results.

Migrating Northwind to the SQL Azure Server

Like mentioned earlier, currently, you cannot take the DB script of say Northwind and run it in the SSMO to be able to create the database in SQL Azure.  There are a few changes required and also few modifications in the script.  Now, doing it for a simple database is quite easy.  However, if you want to migrate a database such as Northwind or Adventure Works, its going to get very complicated and a probable nightmare for you.

Thankfully, there is a SQL Azure Migration Wizard (beta) being developed in CodePlex which is free, open source and under development.  You can view and download it from CodePlex  (Note that it is in Beta and has limited capability in terms of performance, features etc.,)

You can run the SQLAzureMW.exe that gets downloaded once you install the above.  It opens up a screen for connecting to your SQL Server Database

image

Click on “Connect to Server” and specify the servername, credentials etc., and it would list all the databases available in your SQL Server instance.  Click on “Northwind” (this post assumes you already installed the Northwind sample database for SQL Server. If not you can download it from here ) and chose the “Next” step.  It shows the “Script Options” screen where you can change settings.  Clicking on “Next” brings up the screen to chose Object types (SPs, Views, Tables).  I chose, “Script all Object types”

 

image

The next screen provides you to Script it to Window / SQL Azure or to a File.   Chose the “Window / SQL Azure” (default) and click “Next”.  The next screen provides an option to review the configurations made so far.   Click on “Script” and it would parse the scripts and provide the Results Summary.  What this tool essentially does is to make your regular DB Script compatible with a format that is supported in SQL Azure.   Once again since this is in Beta, it may not be near to 100% perfection in this process.

image

The next screen is where you specify your SQL Azure Server Details. Note that the default Server URL that comes is little outdated.  You can get the correct URL from the SQL Azure Portal page (explained in screen shot 2 above) by clicking on the “Connection Strings” icon in the top of the page.  It provides the Server URL as mentioned earlier <YOURSERVERNAME>.ctp.database.windows.net.  You just need to add tcp.  So the fully qualified URL that you need here would look like tcp:<YOURSERVERNAME>.ctp.database.windows.net.  Also, specify the username and password (the one you chose when creating the SQL Azure Database in the first step) and then click on “Test Connection” to check the details.  If you receive an error it might just be wrongly specified server name or missing parts of the URL.   Once you succeed, you can see that it also lists the existing databases (if you haven’t created anything, only “master” would be listed here) and provides the option to create a new database.  You can chose the “Northwind” if you already created it in the SQL Azure portal or type “Northwind” to create it newly.    

image

Next, you can click on “Script” and it does a migration of the scripts to SQL Azure Portal.  It lists down the results in the final screen.

image

Note that this has just migrated the Schema and not the actual Data.  But to take up an on-premise database, generate the scripts and deploy it on SQL Azure manually would be next to impossible, particularly if you have a large database with complex schema.  This tool would help to a great extent in automating the process. 

UPDATE: The latest version of SQL Azure Migration Wizard migrates both Data and Schema.  You can download the same from http://sqlazuremw.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=32334

Finally, we need to upload the Data.  Lets examine it in the next post.  Read Next Post

Cheers !!!

.NET 3.5 SP1 now available as a Windows Feature in Windows 7 RTM

Recently I upgraded to Windows 7 RTM and started setting up my machine.   The usual set of tools I install are Visual Studio 2008, SQL Server 2008, Expression etc.,  Also, for .NET 3.5 and Visual Studio 2008 I would require to install the respective SP1 releases as well since they are mandatory and contain tons of new features as well.

I had done this in the past in Windows Vista, Windows 7 RC etc., and while I was trying to install .NET 3.5 SP1 on the new Windows 7 RTM, it surprisingly, popped up a message as below:-

image

I then realized that .NET 3.5 SP1 is now available in Windows Features under “Control Panel – Programs – Turn Windows Features on or off”.  All I had to do, was enable it.

Cheers !!!

 

«February»
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213