Windows Phone local database (sqlce): 9. connection strings)

Source: Internet
Author: User
Tags connectionstrings

A newbie recently wants to learn about the Windows Phone database and find some short tutorials. Because it is in English, it is translated by the way. The English level is not good. It is estimated that there are many mistakes in the text. If you have any children's shoes that are unfortunately read, please keep in doubt about the translation quality and give me more advice.

This is the original address: http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--Connection-Strings

The text is as follows:

This is the eighth article in the Windows Phone mango local database (sqlce) series. To get you started using databases in Windows Phone mango, this series of short clips will cover all the things you need to know. I will talk about the use of 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 for database configuration. In the connection string, each parameter is separated by a semicolon, and the parameter values are placed in quotation marks. Some parameters are only applicable to database creation. After database creation, these parameters are ignored. A special format connection string should be like this: "Data Source = 'isostore:/directory/file. SDF '"; Reference: You can look at the msdn document http://msdn.microsoft.com/zh-cn/library/hh202861 (V = vs.92). aspx 2, how to use connectionstrings Example 1: the usage of a parameter string format: "Data Source = 'isostore:/directory/file. SDF '"; Note: IsostoreIndicates the path to isolatedstorage.
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 from the installation folder
String format: "Data Source = 'appdata:/directory/file. SDF '";
Note: Appdata indicates the path to the installation folder

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

private const string ConnectionString = @"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 '"

 

private const string ConnectionString = @"Data Source='isostore:/CountryDB.sdf';Password='MyPassword';";

 

This article talks about the connection string in the Windows Phone mango local database and how to use it. Continue to pay attention to the following articles.

 


 

This is the original address: http://windowsphonegeek.com/tips/Windows-Phone-Mango-Local-Database-SQL-CE--Connection-Strings

The text is as follows:

This is the eighth article in the Windows Phone mango local database (sqlce) series. To get you started using databases in Windows Phone mango, this series of short clips will cover all the things you need to know. I will talk about the use of 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 for database configuration. In the connection string, each parameter is separated by a semicolon, and the parameter values are placed in quotation marks. Some parameters are only applicable to database creation. After database creation, these parameters are ignored. A special format connection string should be like this: "Data Source = 'isostore:/directory/file. SDF '"; Reference: You can look at the msdn document http://msdn.microsoft.com/zh-cn/library/hh202861 (V = vs.92). aspx 2, how to use connectionstrings Example 1: the usage of a parameter string format: "Data Source = 'isostore:/directory/file. SDF '"; Note: IsostoreIndicates the path to isolatedstorage.
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 from the installation folder
String format: "Data Source = 'appdata:/directory/file. SDF '";
Note: Appdata indicates the path to the installation folder

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

private const string ConnectionString = @"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 '"

 

private const string ConnectionString = @"Data Source='isostore:/CountryDB.sdf';Password='MyPassword';";

 

This article talks about the connection string in the Windows Phone mango local database and how to use it. Continue to pay attention to the following articles.

 


 

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.