miércoles, 18 de noviembre de 2009

Installing the AdventureWorks database

Technology: SQL Server 2008

Problem: Install the AdventureWorks database in order to get test information. The AdventureWorks are sample databases provided by Microsoft, and they can be downloaded from codeplex here: http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=MSFTDBProdSamples&DownloadId=86538&FileTime=128993370526430000&Build=15987

Solution:

In this zip you get all the information you need to create a SQL Server 2008 database with sample data: http://msftdbprodsamples.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=34032#DownloadId=86540

After downloading the zip, you have to run the script named instawdb.sql . To do this, you need to:

1) 1. Run it in the SLQCMLD Mode. You do this in SQL Server Manager, by selecting Query -> SLQCMLD Mode

2) 2. Enable FILESTREAM. Here it is explained how to achieve this:

http://techpunch.wordpress.com/2008/08/29/how-to-enable-filestream-feature-on-sql-server-2008/

3) 3. Make sure the process has access to the folder in which the MDF file is going to be created (you assure this by giving to everyone group the full access permission to the folder in which the MDF is going to be created– you could remove this afterwards)

4) 4. Uncomment the setvar lines, and make sure that both paths are correctly set with the information that is in the .zip:

:setvar SqlSamplesDatabasePath "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

:setvar SqlSamplesSourceDataPath "C:\Program Files\Microsoft SQL Server\100\Tools\Samples\"

viernes, 13 de noviembre de 2009

Save/Read a file from Silverlight 3.0 in the client machine

Problem: For security reasons, it is not allowed to save a file in any part of the client’s file system using FileStream class or similar. To achieve this, you can either use IsolatedStorage, or the Save/Open File Dialogs added in Silverlight 3.0 version.

Solution 1: Using Isolated Storage

Isolated Storage allows you to read/write files in the client machine, but on a folder Silverlight designates. This could be useful to implement a disk cache, for instance.

The folder in which the file is stored is not intended for the user to access. Its name is something like this: AppData\LocalLow\Microsoft\Silverlight\is\ngns4lzo.xrg\24n0wuei.lxq\1\s\s03b4fsd1eqjjyya0pbbphul0qd3a5mowxinuc0cprdrsg1fp0aaacga\f

Usage example:

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();

IsolatedStorageFileStream fs = new IsolatedStorageFileStream("tst.txt",FileMode.Create,FileAccess.Write, FileShare.ReadWrite, file);

IsolatedStorageFileStream inherits FileStream.

Solution 2: Using SaveFileDialog / OpenFileDialog (available from Silverlight 2.0/3.0 version)

In order to save or read files from any given location in the client machine, you need to use SaveFileDialog / OpenFileDialog. These are used in a similar way to the Windows Forms open/save dialogs.

With both dialogs, the only available operations are OpenDialog and a Stream property to which you could write or read.

Limitations of this solution: Because of security reasons, the dialog can only be initiated by the user.Therefore Open/Save dialogs can only be called from event handlers such as button clicks.

You cannot debug the method in which the open or save file dialogs are opened, and you cannot open two file dialogs on the same handler, otherwise you will get this error: “Dialogs must be user-initiated”