A tour of deploying ASP. NET SQLite applications in Linux with demo and source code

Source: Internet
Author: User
Tags vps

A tour of deploying ASP. NET SQLite applications in Linux with demo and source code

A bumpy journey to deploy ASP. NET SQLite applications in Linux. The sample code is provided at the bottom of the article.

There was an idle Linux VPS, trying to deploy the. NET program, and the result was a pitfall, but finally it was a perfect solution. The record is as follows.

Environment: CentOS 6 mono version mono-3.2.1 jexus version jexus-5.6.4

1. installation environment

1. Install mono

First install the system environment:

Yum-y install gcc-c ++ bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel giflib-devel libX11-devel freetype-devel fontconfig-devel cairo-devel

Download mono installation:

Wget http://download.mono-project.com/sources/mono/mono-3.2.1.tar.bz2tar-jxvf mono-3.2.1.tar.bz2cd mono-3.2.1. /configure-prefix =/usrmake the following error occurs at this time .. /src /. libs/libeglib. a (libeglib_la-gunicode.o): In function 'monoeg _ g_get_charset':/root/mono-3.2.1/eglib/src/gunicode. c: 223: undefined reference to 'locale _ charset' collect2: ld returned 1 exit status make [4]: *** [test-eglib] Error 1 make [4]: leaving directory '/root/mono-3.2.1/eglib/test' make [3]: *** [all-recursive] Error 1 make [3]: leaving directory '/root/mono-3.2.1/eglib' make [2]: *** [all] Error 2 make [2]: leaving directory '/root/mono-3.2.1/eglib' make [1]: *** [all-recursive] Error 1 make [1]: leaving directory '/root/mono-3.2.1' make: *** [all] Error 2 modify eglib/config. hvi eglib/config. h. Replace # define HAVE_LOCALCHARSET_H 1 with # define HAVE_LOCALCHARSET_H 0 makemake installmono-V. This step shows that the installation is successful.

2. Install jexus

cd /tmpwget linuxdot.net/down/jexus-5.6.4.tar.gz tar -zxvf jexus-5.6.4.tar.gz cd jexus-5.6.4 sudo ./install 

Jexus-related configuration instructions: http://www.linuxdot.net/bbsfile-3084

Ii. Code

 

There are two ways to enable asp.net to operate sqlite on Linux.

Because Linux comes with the sqlite environment, you do not need to install the environment. Windows does not need to install sqlite or download sqlite3.dll.

This example is developed using WebForm.

 

1. Use the built-in Mono. Data. Sqlite

The usage is the same as that of Ado. Net. I will not explain it too much here.

Mainly in the Link string section "Version = 3; Data Source = {file path }"

 

2. Use sqlite-net in NuGet (the final method is perfect)

Install-Package sqlite-net

Github: https://github.com/praeclarum/sqlite-net

Wiki: https://github.com/praeclarum/sqlite-net/wiki

After installation, you can develop the SDK. The wiki provides detailed usage instructions.

 

I just implemented some simple addition, deletion, query, modification operations.

Usage:

[PrimaryKey, AutoIncrement] // Add an auto-incrementing public int ID to the primary key {get; set ;}

For more methods, see wiki.

Basic Code

Public partial class Demo: System. Web. UI. Page
{
Private SQLiteConnection con = null;
Protected void Page_Load (object sender, EventArgs e)
{
Var path = Server. MapPath ("~ /App_Data/Demo. db ");
Con = new SQLiteConnection (path );
// Con. CreateTable <User> (); // only one operation is required to create a table.

If (! String. IsNullOrEmpty (Request ["id"])
{
Con. Delete <User> (Request ["id"]);
Response. Redirect ("Demo. aspx ");
}

Var cmd = con. CreateCommand ("select * from User ");
Var list = cmd. ExecuteQuery <User> ();
Foreach (var item in list)
{
Response. Write (string. Format ("{0}-{1}-{2} <a href = 'demo. aspx? Id = {3} '> Delete </a> <br> ", item. Name, item. PassWord, item. CreateTime, item. ID ));
}
}

Protected void BtnAdd_Click (object sender, EventArgs e)
{
Var rand = new Random (). Next (1, 100,999 );
User user = new User ();
User. Name = "ceshi" + rand;
User. PassWord = "123456" + rand;
User. CreateTime = DateTime. Now;
Con. Insert (user); // Add data
Response. Redirect ("Demo. aspx ");
}
}

The final program is uploaded to the vps using winscp. Perfect for running on linux.

Run:

The system above is identified as linux.

Iii. Summary

Asp.net mvc 5.0 and later versions are not particularly well supported in the linux mono environment.

Thanks @ Zhang Shanyou for reminding me that Windows is case insensitive and Linux is case sensitive. Therefore, the path must be case-insensitive.

Finally, I would like to thank all the predecessors on the Internet for their selfless sharing. Special thanks to garden @ Zhang Shanyou for sharing.

Source Code address: https://github.com/linezero/sqlitedemo

This article permanently updates the link address:

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.