Design Time Support for Data in Blend and Visual Studio 2010

by Shawn January 13, 2010 06:36

Tags: , , , ,

Development

SQLite and Visual Studio 2010/.NET 4.0

by Shawn December 10, 2009 07:54

SQLite is one of those gems in the development community. When you need a small, lightweight, fast, and FREE embedded database there is nothing better out there.  To top it off, the guys at PhxSoftware have done an absolutely fantstic job of creating a complete ADO.NET 2.0 data provider for SQLite.  The only downside right now is that it has not been updated for .NET 4.0 and Visual Studio 2010.  That said for those of you chomping at the bit to work in the latest and greatest there is no need to fear as we have a work around to get you up runnng.

If you are gettting this exception:

System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional configuration information.

There is a solution that was first pointed out by Jomo Fisher. All you need to do is to include this snippet in the application config file:

<startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0"/>
</startup> 

Now, that said if you really want a native version it is possible as apparently recompiling the project and targeting .NET 4 works

  1. In order to compile sqlite.net with vs2010 beta 2 you can convert the 2008 solution. Before you convert the project files, you will need to remove the compact framework targets or the conversion will fail telling you that the compact framework is not supported.
  2. After the projects are converted set the targeted framework to .net 4

I could not get the netmodule to compile in vs2010 (it complained that the OutputType was not supported) but the netmodule will build when build from the command line with msbuild. The rest of the projects compile fine.

To get the designer to compile you will need to add a file called source.extension.vsixmanifest.The next thing I encountered was a System.TypeLoadException (Inheritance security rules violated by type). This could be solved by adding the following line to System.Data.SQLite/AssemblyInfo.cs

[assembly: SecurityRules(System.Security.SecurityRuleSet.Level1)]

There are some more minor changes to the project files to get it to compile but in the end it compiles with .NET 4 support and works without workarounds when used from .NET 4.

Tags: ,

Development

A useful tool set for working with DBF files

by Shawn November 30, 2009 06:25

CDBF from WhiteTown

cdbfwgui.zip (2.29 mb)

DBFViewer from cooolutils

DBFViewer.exe (1.62 mb)

And a nice shell extension for getting quick information about a DBF file

cdbfinfo.zip (341.77 kb)

Tags:

Development

How to Alter a SQL Server Database as Single User Mode and as Multi User Mode

by Shawn November 20, 2009 01:51

Original Link: http://www.kodyaz.com/articles/alter-single-user-multi-user-mode.aspx

You can use the SQL Server Enterprise Manager for SQL Server 2000 to set a database to a single user mode or to multi user mode. Similarly, SQL Server Management Studio can be used for SQL Server 2005 for changing a database to single user mode or to multi user mode. Also you can alter the database access mode by using sql commands like ALTER DATABASE and sp_dboption.

 

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT

or

EXEC sp_dboption 'Works', 'single user', 'false'

EXEC sp_dboption 'Works', 'single user', 'true'

To alter the database state to restrict the access to the single user mode, first open the Microsoft SQL Server Management Studio, and connect to a SQL Server instance. Open the list of available databases belonging to the related instance in the Object Explorer window. Right click on the sql server database that you want to set its mode to single user and select Properties in the context menu.

When you click properties menu item, the following Database Properties screen will be displayed for the selected database. I used database named Works for samples used for the article.

restrict access

Select the Options page from the list in the left side of the screen. If you scroll down the options list for State options, you will see Restrict Access database options with three options listed in the combo box.

Restrict Access modes : Multiple, Single and Restricted modes.

 

If you select Single mode and click the OK button, you can either alter the database access mode to single user successfully or you will fail to change the access mode because of existence of active open connections to the Works database. The Management Studio IDE will prompt you to close all other connections to the related database for a successfull alter database option process.

open connections

To change the database properties, SQL Server must close all other connections to the database. Are you sure you want to change the properties and close all other connections?
 

After the alter command runs successfully, the database Works will be displayed as shown in the Object Explorer window.
single-user

 

If an active connection exists other than the Management Studio, and you click the database Works within the SQL Server Management Studio, the following warning message will be displayed:


database-is-not-accessible

The database Works is not accessible. (ObjectExplorer)

 

If you right click on the database Works, the following error message will be displayed.

database-is-already-open

Database 'Works' is already open and can only have one user at a time. (Microsoft SQL Server, Error: 924)

 

After a database is altered as single user mode, it can be altered again back to multi user mode by running the below sql command.

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

But if this command is run from a connection that is not the only active connection to the related database, the command will fail with the following message:

Msg 5064, Level 16, State 1, Line 1
Changes to the state or options of database 'Works' cannot be made at this time. The database is in single-user mode, and a user is currently connected to it.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.

 

 

In a case that you want to alter the database access mode from single user mode to multi user mode or from multi user mode to single user mode, you may have to kill all the active open connections to the database.

In such a case, you have to find all the open connections and run "Kill @spid" command to close all the connections.

For a list of open connections for a specific database you can run a similar command as below :

select spid from master..sysprocesses where dbid = db_id('Works') and spid <> @@spid

The second part of the task will be closing the open connections with the Kill command. This can be achived by running kill commands within a cursor or creating a dynamic sql command which kills the active connections to the related database.

Let's code the closing open connections using a t-sql cursor:

DECLARE @DatabaseName nvarchar(50)
DECLARE @SPId int

SET @DatabaseName = N'Works'

DECLARE my_cursor CURSOR FAST_FORWARD FOR
SELECT SPId FROM MASTER..SysProcesses WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

OPEN my_cursor

FETCH NEXT FROM my_cursor INTO @SPId

WHILE @@FETCH_STATUS = 0
BEGIN
KILL @SPId

FETCH NEXT FROM my_cursor INTO @SPId
END

CLOSE my_cursor
DEALLOCATE my_cursor

 

After all connections are closed except the currently running prcess (@@spid) if we are trying to alter the access mode of the database that we're in from multi user mode to single user mode, we can now run the ALTER DATABASE command for single user mode or multi user mode.

ALTER DATABASE [Works] SET MULTI_USER WITH NO_WAIT

or

ALTER DATABASE [Works] SET SINGLE_USER WITH NO_WAIT

 

You can also use the following sp_dboption sql commands to alter the database option for single user. If you set the "single user" database option to "true", this is same as altering the database as "SINGLE_USER" with ALTER DATABASE statement.


USE master
GO
EXEC sp_dboption 'Works', 'single user', 'false';


If you run the below sp_dboption command which sets the "single user" to "false", this is same as altering the database as "MULTI_USER" with ALTER DATABASE statement.


USE master
GO
EXEC sp_dboption 'Works', 'single user', 'true';

 

The main difference between sp_dboption and ALTER DATABASE commands is that, sp_dboption will not be supported with further releases of SQL SERVER after SQL SERVER 2005.

Tags:

Development

Generic Databinding with Silverlight

by Shawn June 01, 2009 06:22

This is one of those missing features that really makes you ask "what are they thinking" -- complex business systems that allow for on the fly customizations (something that is very common today) need to be able to be handled in Silverlight.

So if you are running into this and not sure how to proceed, here are some links that you might find useful

http://silverlight.net/forums/t/16733.aspx
http://silverlight.net/forums/t/63057.aspx
http://silverlight.net/forums/t/11570.aspx

http://silverlight.codeplex.com/WorkItem/View.aspx?WorkItemId=2810

Tags: ,

Development

How to Resolve WCF Issue: Can't host WCF service in a website with multiple identities

by Shawn April 28, 2009 08:18

When a WCF service is hosted in a IIS website which has multiple identities, that is, responds on different hostnames/ports, the WCF service, when created, throws the exception below:

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

I am aware that this behavior is by design and I believe that it can be resolved. I'm searching to forums, MSDN and blogs but no solution was found. I'm only found one solution to create a custom ServiceHostFactory which filters the additional base addresses and instantiates the service on one of them only. Thank to Zeddy for the helps. This issue can be resolved by creating a custom ServiceHostFactory which clear all baseAddresses then override Behaviors and ServiceEndPoint described below.

Create Custom ServiceHostFactory

Create new class for custom ServiceHostFactory below.

using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Linq;
using System.ServiceModel.Description;

public class MultipleIISBindingSupportServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        // return the emply list Uri to make it automatically select baseAddresses by endpoint configuration
        var host = base.CreateServiceHost(serviceType, new Uri[] {/*empty*/ });

        // Setup MEX dynamically
        var behavior = new ServiceMetadataBehavior
                           {
                               HttpGetEnabled = true,
                               HttpGetUrl = baseAddresses.Where(addr => addr.Scheme == "http").First()
                           };
        host.Description.Behaviors.Add(behavior);
        
        // Setup Endpoint configuration dynamically
        foreach (var uri in baseAddresses)
        {
            // Service endpoint support http scheme only, exclude https scheme
            if (uri.Scheme == "http")
            {
                host.AddServiceEndpoint(serviceType,
                                        new BasicHttpBinding(BasicHttpSecurityMode.None),
                                        uri
                    );
            }
        }
        return host;
    }
} 

Modify WCF Service Markup

To modify WCF Service Markup, right click on the MyService.svc file and then click "View Markup".

<%@ ServiceHost Language="C#" Debug="true" Service="MyService" CodeBehind="MyService.svc.cs" Factory="MultipleIISBindingSupportServiceHostFactory" %>

Modify Web.config File

Open web.config file and going to line with <system.serviceModel> element, replace <system.serviceModel> and all child elements with following config.

<system.serviceModel>
	<diagnostics>
		<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/>
	</diagnostics>
	<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

After all steps above was done, the multiple identities issue should be resolved.

I hope this tips will be helpful.

Tags: ,

Development

Creating and Handling Faults in Silverlight

by Shawn April 28, 2009 06:52

Tags: , ,

Development

How to handle: An error occured creating the configuration section handler for system.serviceModel/behaviors…

by Shawn April 28, 2009 06:49

Are you developing an extension to Windows Communication Foundation (for example a behavior or message encoder) with configuration file support? If you are you may be getting frustraited by an exception something like the following (the precise nature depends on the kind of extension you are developing).

I was, and the frustraiting thing was that I had built some of these in the past for various purposes without any issues so I had a real tough time figuring out what the hell was going on. Well it turns out that it is a string comparison issue. Lets take a look at the configuration file for a WCF service:

In this configuration file I have a simple math service but I have applied an endpoint behavior to it called “beep” in the configuration file. This is a custom behavior so I’ve had to implement my own BehaviorExtensionElement and in this case I’ve implemented the element and the actual IEndpointBehavior in the same class (because I can). What happens is when WCF initialises it loads in the list of the extensions into a hashtable (simplication - there is a lot more code involved than just a hashtable-like data structure) - so in this case “beep” is mapped to “ServerApplication.BeepBehavior….”, at the same time an instance of the class specified in the second value is instansiated and stored.

As execution continues and the service host is brought online the <beep /> element is encounted. The aforementioned hashtable is looked up and the fully qualified class name is retreived. This is then used as a key to find the custom BehaviorExtensionElement and this is where it comes unstuck. When the BehaviorExtensionElement is stored it is indexed with the fully qualified type name which is fetched using .GetType(), when this value is rendered as a string it looks like this:

ServerApplication.BeepBehavior, ServerApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Notice the spaces between each of the type name elements. Now - compare this to the screenshot of the configuration file above. As you can see there is no space between the type name elements. Since the lookup is based on a simple string comparison the space is significant and the WCF runtime can’t find the previously created BehaviorExtensionElement instance and it all falls in a heap - if you go and put the spaces in it works perfectly.

The frustraiting thing is that the space sensitivity of the type attribute in the WCF portions of the configuration files is completely at odds with the norms in the rest of the .NET Framework (although I am aware of some similar issues in WPF thanks to Darren). Unfortunately it looks like Tomas Restrepo found the issue as well in this feedback entry on Microsoft Connect - but it looks like all development was closed off and it obviously shipped with this quirk.

Personally I think that this needs to be treated as a bug and fixed as soon as possible because it is going to drive developers who try to extend WCF completely nuts and when they realise what the problem was the WCF team better hope they are no where within reach. Given it isn’t a critical bug I suspect that it may have to wait for a service pack to be issued though.

Reprint from:
http://notgartner.wordpress.com/2006/12/19/rant-an-error-occured-creating-the-configuration-section-handler-for-systemservicemodelbehaviors/

Tags: ,

Development

A fantastic example of what Silverlight 3 can do

by Shawn April 16, 2009 03:06

I highly encoruage everyone to check out Mike Harsh's sample application Slidentiy.  It does a great job of showing what is possible with Silverlight and best of all it comes with the source code in by C# and VB.NET

 http://silverlight.net/learn/appcorner/slidentity.aspx?pt=slidentity

Tags:

Development

Overview of SharePoint Architecture

by Shawn March 25, 2009 06:54

Microsoft recently posted two great articles that go over the architecture for SharePoint for an IIS and Development perspective.

Part 1: http://msdn.microsoft.com/en-us/library/bb892189.aspx
Part 2: http://msdn.microsoft.com/en-us/library/bb892187.aspx

 

Tags:

Development | SharePoint

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant