Ef+sqlite setting the connection string dynamically

Source: Internet
Author: User
Tags sqlite connectionstrings

Summary

When doing the C/s project, if you use Ef+sqlite, we do not know where the client will be installed, and need to dynamically set the path of the db.

Solutions
    /// <summary>    /// Data Context     /// </summary>     Public class Mycontext:dbcontext    {                public  mycontext ()            base(new sqliteconnection (  @ "Data source=c:\users\wolfy\appdata\local\client\data\my.db; "),false)        {        }           }

It is necessary to mention another way of setting

< connectionStrings >    <  name= "ConnStr"  connectionString= "Data source=| Datadirectory|\my.db "  providerName=" System.Data.SQLite.EF6 "/>  </ connectionStrings >

DataDirectory can be set in the program

AppDomain.CurrentDomain.SetData ("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);

Found this way, set in the EXE directory under the function, but change the directory seems to be invalid. Guess, the way SQLite looks for database files, it should be found by default from the directory where the EXE.

Reference

Http://www.cnblogs.com/liuguangyin/p/6572734.html

Ef+sqlite setting the connection string dynamically

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.