转贴:SQLite——只要3分钟,你就可以在.NET上创建和运行它
2008-07-22 18:25
288 查看
来自:http://www.mikeduncan.com/sqlite-on-dotnet-in-3-mins/
You found it! The quick and dirty guide to setting up SQLite with .Net in 3 minutes. Small, fast, and ass-kicking like a transactional Jackie Chan. At least that’s what this campy image created just for this post says. (Shout out to righteous graphics dude Brian Cook for the sweet photoshoppery)
public static DataTable GetDataTable (string sql)
public static int ExecuteNonQuery(string sql)
public static string ExecuteScalar(string sql)
{
SQLiteConnection cnn = new SQLiteConnection("DataSource=C:CheckoutWorldDominator.s3db");
cnn.Open();
SQLiteCommand mycommand = new SQLiteCommand(cnn);
mycommand.CommandText = sql;
object value = mycommand.ExecuteScalar();
cnn.Close();
if (value != null)
{
return value.ToString();
}
return "";
}
NOTE: Above code is quicky crap. It’s just to show you the gist.
Some uses for SQLite to consider:
Configs / Settings: SQLite is a good alternative to xml config files or registry settings for things like user account info and application preferences. It supports encryption, so feel free to keep your brilliant patent ideas in there.
Persistent Caching: You can use SQLite as a DB for cache data that needs to persist through reboots / application recycles. Maybe you have some expensive one-time-on-loadup queries from your enterprise db that you cache up and use in your website or app. By timestamping the data into a local SQLite db, you can live through application restarts and only refresh your cache at the threshold you want to.
Slicing and Dicing data: Load in some data and query to your heart’s content. Great for analyzing data at your leisure, worming through subsets of data, etc. Since its just a little db on your on box, no one is going to hassle you. Managers who were once developers will appreciate being to query through data with SQLite vs. using excel as they usually are too crusty to still have permissions on the real db.
Full DB for One-off apps: Sometimes you write a quickie app that just harvests something in a funky way and collects data. You can output the data as you are grabbing it in all kinds of ways, but throwing into a db is ideal.
Linkage to some more in-depth stuff ……….
- SQLite is pretty hip with with the alt.net scene, you can follow on from here to check out a SQLite NHibernate provider, or here for a SQLite Subsonic provider.
- If you are rockin’ the 3.0 framework there is even a SQLite Linq provider.
- For a comprehensive SQLite how-to (emphasizing command line, non-MS specific) : SQLite Tutorial
- And in case you missed it up top, the main SQLite project page is here.
Have a good idea for ways to use SQLite in .Net projects? Been hit in the groin with a football for even suggesting using something like this at your company? Have some award-winning successes or outlandish failures already with SQLite? Leave a funky-fresh comment!
SQLite on .NET - Get up and running in 3 minutes.
January 15th, 2008 | grokableYou found it! The quick and dirty guide to setting up SQLite with .Net in 3 minutes. Small, fast, and ass-kicking like a transactional Jackie Chan. At least that’s what this campy image created just for this post says. (Shout out to righteous graphics dude Brian Cook for the sweet photoshoppery)
public static DataTable GetDataTable (string sql)
public static int ExecuteNonQuery(string sql)
public static string ExecuteScalar(string sql)
{
SQLiteConnection cnn = new SQLiteConnection("DataSource=C:CheckoutWorldDominator.s3db");
cnn.Open();
SQLiteCommand mycommand = new SQLiteCommand(cnn);
mycommand.CommandText = sql;
object value = mycommand.ExecuteScalar();
cnn.Close();
if (value != null)
{
return value.ToString();
}
return "";
}
NOTE: Above code is quicky crap. It’s just to show you the gist.
Some uses for SQLite to consider:
Configs / Settings: SQLite is a good alternative to xml config files or registry settings for things like user account info and application preferences. It supports encryption, so feel free to keep your brilliant patent ideas in there.
Persistent Caching: You can use SQLite as a DB for cache data that needs to persist through reboots / application recycles. Maybe you have some expensive one-time-on-loadup queries from your enterprise db that you cache up and use in your website or app. By timestamping the data into a local SQLite db, you can live through application restarts and only refresh your cache at the threshold you want to.
Slicing and Dicing data: Load in some data and query to your heart’s content. Great for analyzing data at your leisure, worming through subsets of data, etc. Since its just a little db on your on box, no one is going to hassle you. Managers who were once developers will appreciate being to query through data with SQLite vs. using excel as they usually are too crusty to still have permissions on the real db.
Full DB for One-off apps: Sometimes you write a quickie app that just harvests something in a funky way and collects data. You can output the data as you are grabbing it in all kinds of ways, but throwing into a db is ideal.
Linkage to some more in-depth stuff ……….
- SQLite is pretty hip with with the alt.net scene, you can follow on from here to check out a SQLite NHibernate provider, or here for a SQLite Subsonic provider.
- If you are rockin’ the 3.0 framework there is even a SQLite Linq provider.
- For a comprehensive SQLite how-to (emphasizing command line, non-MS specific) : SQLite Tutorial
- And in case you missed it up top, the main SQLite project page is here.
Have a good idea for ways to use SQLite in .Net projects? Been hit in the groin with a football for even suggesting using something like this at your company? Have some award-winning successes or outlandish failures already with SQLite? Leave a funky-fresh comment!
相关文章推荐
- SQLite——只要3分钟,你就可以在.NET上创建和运行它
- SQLite——只要3分钟,你就可以在.NET上创建和运行它
- SQLite——只要3分钟,你就可以在.NET上创建和运行它 -------------转载
- SQLite——只要3分钟,你就可以在.NET上创建和运行它
- .Net集合类型大全,只要灵活运用可以节省很多开发时间和提高程序运行效率
- .net中实现运行时从字符串动态创建对象 (转)
- .net运行网站时出现未能创建Mutex解决办法
- 不装mono,你的.NET程序照样可以在Linux上运行!
- 创建线程后为什么关闭了线程句柄,线程还是可以运行?
- Collection -> .Net集合类型大全,只要灵活运用可以节省很多开发时间和提高程序运行效率
- 在VC2005中,只要知道类的名字,就可以动态创建类的实例
- 创建线程后为什么关闭了线程句柄,线程还是可以运行?
- .net中实现运行时从字符串动态创建对象
- 不装mono,你的.NET程序照样可以在Linux上运行
- 在Windows上创建可以运行在U盘上的Ubuntu系统
- .net中实现运行时从字符串动态创建对象
- 创建线程后为什么关闭了线程句柄,线程还是可以运行?
- 如何实现.net下开发的程序脱离.net环境运行并且可以跨平台的想法
- c# sqlite 数据库加密2010-05-29 10:55用了ADO.NET 2.0 SQLite Data Provider 这样可以直接利用它来创建一个加密的sqlite数据库。
- 不装mono,你的.NET程序照样可以在Linux上运行!