Showing posts with label .NET. Show all posts
Showing posts with label .NET. Show all posts

Thursday, August 27, 2009

Location of IsolatedStorageFile

An IsolatedStorageFile is always persisted to a dedicated location by .NET isolated storage API. Each file, when it is first created, will be granted access at least to the current logged-on user plus other requirements. In other words, an IsolatedStorageFile is created based on isolated requirements called IsolatedStorageScope, for example,

  • User + Assembly
  • User + Assembly + Domain
  • Roaming + User + Assembly
  • Roaming + User + Assembly + Domain
  • ...
  • Machine + Assembly +
  • Machine + Assembly + Domain
  • ...
Note that you cannot initialize a storage with IsolatedStorageScope.User and IsolatedStorageScope.Machine together because IsolatedStorageScope.Machine represents All Users which include the current user. But either one of them must be present in the IsolatedStorageScope with others. In addition, you cannot use IsolatedStorageScope.Application if the application is not configured or running as a ClickOnce application, which implies you can only use either IsolatedStorageFile.GetUserStoreForApplication() or IsolatedStorageFile.GetMachineStoreForApplication() for store initialization only when the application is NOT a ClickOnce application.

The exact location to represent the isolated storage "file system" varies from operating systems.

For user scope (IsolatedStorageScope.User) related, the isolated storage is located at

   XP: %USERPROFILE%\Local Settings\Application Data\IsolatedStorage\
Vista: %USERPROFILE%\App Data\Local\IsolatedStorage\ 
For machine or all users scope (IsolatedStorageScope.Machine) related, the isolated storage is located at
   XP: %ALLUSERSPROFILE%\Local Settings\Application Data\IsolatedStorage\
Vista: %ALLUSERSPROFILE%\App Data\Local\IsolatedStorage\ 
All storage entry points (folders) will be placed under the above location(s). Each of entry point or folder represents a store assigned or automatically created by .NET when an IsolatedStorageFile is first created. Then you can create folders or sub-folders relative to that store location. After that, you can even create another IsolatedStorageFiles under those sub-folders.

Sunday, May 3, 2009

LINQ and ConnectionString

There are some issues you should know when you are working with Database Markup Language(DBML) or generating LINQ to SQL classes in VS.2008 IDE:

Why is the dropdown box of "Choose your context object" always empty or why can't I find my context object while I am configuring LinqDataSource?

Why do I have this error "No parameterless constructor defined for this object"?

Why does the actual connection string suddenly appear inside the parameterless contructor of my DataContext class?

Why can't I add a database table to DBML / LINQ designer?



  1. Why is the dropdown box of "Choose your context object" always empty or why can't I find my context object while I am configuring LinqDataSource?

    Please be sure the DLL containing the context object existed and you have a reference to it. If the LINQ class is newly created, please compile the project first before you try to configure LinqDataSource.

  2. Why do I have this error "No parameterless constructor defined for this object"?

    If you remove the ConnectionString manually from the Connection element of the DBML source file first (use external text editor to remove it) and then set the Application Settings to False (also see How to Turn off Application Settings for LINQ), your parameterless constructor of the DataContext class (e.g., Book.designer.cs) will immediately be removed by the IDE. Then the above error will occur when you recompile and run the application.

    Normally enabling Application Settings on LINQ will have the parameterless constructor generated for you automatically, as long as its ConnectionString property is not empty. Indeed, you won't be able to remove the ConnectionString property inside the IDE.  But you remove it anyway outside it. When this happens, the original parameterless contructor will lose forever regardless of Application Settings. Thereafer, adding back the ConnectionString property to the file will not resolve it. And the other problem dicussed in the next question may occur.

    To resolve this, you need to manually add the original parameterless constructor back.

  3. Why does the actual connection string (like below) suddenly appear inside the parameterless contructor of my DataContext class? For example,
        public BookDataContext() :
            base("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Books.mdf;Integrated Security=True;User Instance=True", mappingSource)
        {
            OnCreated();
        }

    Situation 1:    If you set the Application Settings to False while the ConnectionString property exists in the DBML source file, your original parameterless constructor of that DataContext class will be altered by hard-coding with the actual connection string that can be found in your .config file (e.g., web.config).

    Situation 2:    The application had Application Settings set to False and the correct default parameterless constructor some time ago. Later, you make a change by adding a new table to the LINQ. As soon as you drag the new table to the DBML or LINQ designer, your original, correct parameterless contructor will be altered by hard-coding with the actual connection string.

    Currently, I don't know any other easy way to deal with it. If you know, please jot me a note. What I do is

    1. First, ensure Application Settings for LINQ is set to False.
    2. Then, manually alter or copy the parameterless contructor back to the original
    3. .

  4. Why can't I add a database table to DBML / LINQ designer?

    This happens when

    • your Application Settings for LINQ is set to False,
    • ConnectionString element doesn't exist in the DBML source file, and
    • the parameterless constructor in LINQ class is missing.

    The IDE needs to know where to read the connection string in order to access the database. Please ensure you have the parameterless contructor defined correctly while remaining Application Settings for LINQ to False and the absence of ConnectionString in the DBML source file.

Sample of Parameterless Constructor in a ContextClass

public BookDataContext() :     base(global::System.Configuration.ConfigurationManager.ConnectionStrings["BookConnectionString"].ConnectionString, mappingSource) {     OnCreated(); } where BookDataContext is my DataContext class, BookConnectionString is the name of the connection string found in .config file. You should change them to fit yours accordingly.

How to Turn off Application Settings for LINQ
The default setting of LINQ to SQL class is always True. You can do the following to disable it.

On VS IDE
  • Go and double-click to open the DBML file from Solution Explorer.
  • Then open the file Properties window if it is not open. Be sure that the focus is on the DBML designer tab; otherwise, you won't see or cannot continue with the next step.
  • Expand Connection and then set Application Settings to False.

Friday, April 10, 2009

Windows Firewall Settings and IIS for ASP.NET

If you are using the built-in internal development/test server in Visual Web Developer Express or VS.NET for development, testing and debugging, there is nothing you should worry about the Windows Firewall settings. However, if you would like to test your Web application over the network on a local IIS Web server, you need to have the following setting changed on Windows Firewall setting:

On Windows XP,

  • Go Control Panel -> Windows Firewall
  • Select Advanced tab
  • On the Network Connection Services selection list, select one of the connection item, e.g., Local Area Connection, Wireless Network Connection, ... and etc.
  • Then click Settings...
  • Ensure that Web Server (HTTP) is checked.

On Windows Vista,

  • Go Windows Control Panel
  • Select the Exception tab
  • Ensure that World Wide Web Services (HTTP) is checked.