Windows phone Local Database (SQLCE): 9, Connection Strings (translation)

Source: Internet
Author: User
Tags string format connectionstrings

This is the eighth article in the "Windows Phone Mango Local Database (SQLCE)" series. To get you started using the database in Windows Phone Mango, this series of short film articles will cover all the knowledge you need to know. I'll talk about using connection strings in the Windows Phone Mango Local database.

1. What is connectionstrings?before we actually start using a database, we need to develop a connection string that tells the application how to connect to the database. A connection string can be used to make a database configuration value. In the connection string, each parameter is separated by a semicolon, and the value of the parameter is enclosed in quotation marks. Some parameters apply only to creating a database, and after the database is created, these parameters are ignored. The connection string for a particular format should look like this: "Data source= ' isostore:/directory/file.sdf '"; Reference : You can look at the MSDN documentation http://msdn.microsoft.com/zh-cn/library/hh202861 (v=vs.92). aspx2. How to use connectionstringsExample 1: Use of a parameterString Format: "Data source= ' isostore:/directory/file.sdf '"; Note : isostore represents a path to IsolatedStorage?
12345678910111213141516 private const string ConnectionString = @"isostore:/CountryDB.sdf"; public MainPage() {     InitializeComponent();        using (CountryDataContext context = new CountryDataContext(ConnectionString))     {            if (!context.DatabaseExists())         {             // create database if it does not exist             context.CreateDatabase();         }     } }
Example 2: Read String format: "Data source= ' appdata:/directory/file.sdf '" from the installation folder; Note : AppData indicates the path to the installation folder ?
123456789101112131415 private const string ConnectionString = @"Data Source = ‘appdata:/CountryDB.sdf‘; File Mode = read only;"; public MainPage() {     InitializeComponent();        using (CountryDataContext context = new CountryDataContext(ConnectionString))     {            if (!context.DatabaseExists())         {             // create database if it does not exist             context.CreateDatabase();         }     } }

Example 3: A database with a specific culture

?
1 privateconst stringConnectionString = @"Data Source = ‘CountryDB.sdf‘; Culture Identifier = fr-FR; Case Sensitive = true;";

Note : You can refer to the MSDN documentation: Http://msdn.microsoft.com/zh-cn/library/system.globalization.cultureinfo (v=vs.71). aspx

Example 4: Database encryption

String format: "Data source= ' isostore:/dirctory/file.sdf '; password= ' Somepassword ' "

?
1 privateconst stringConnectionString = @"Data Source=‘isostore:/CountryDB.sdf‘;Password=‘MyPassword‘;";

This article I talked about the connection string in the Windows Phone Mango Local database and how to use it. Keep your eye on the next article.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.