Access数据库转换为sdf数据库及SqlCeHelper类
在做Mobile项目时遇到一个问题,我们的Mobile项目需要使用SqlCe数据库,而客户提供的带有原始数据的数据库是Access格式的,所以我们面临的第一个问题是将Access数据库(*.mdb)转换成SqlCe数据库(*.sdf)。网上搜索的很多资料是关于如何将SqlServer 2005与SqlCe数据进行同步,主要是通过发布订阅及RDA编程来实现,可以参考的资料有:
用 SQL Server Management Studio 管理 SQL Server Compact Edition 数据库
SQL CE 和 SQL Server 的同步
Step by Step: Program Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework
后来找到一个工具Data Port Wizard可以直接将其他数据库转换为SqlCe数据库,省了不少事。只是转换过程中遇到一个小小的问题,在客户提供的Access数据库的关系里设置了很多表与表之间的关系,但所有的表都没有设置主键,所以转换时就抛出异常。为了省事,我将Access表的关系全部删除,这样就顺利的将Access数据库转换成SqlCe 3.5版本的sdf数据库了。
至于操作SqlCe的数据层的类,在网上找到一个SqlCeHelper.cs,转贴如下:
using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Configuration;
using System.Collections;
namespace SbuxMobile.DAL
{
///
/// The SqlCeHelper class is intended to encapsulate high performance, scalable best practices for
/// common uses of SqlClient
///
public sealed partial class SqlCeHelper
{
#region private utility methods & constructors
// Since this class provides only static methods, make the default constructor private to prevent
// instances from being created with "new SqlCeHelper()"
private SqlCeHelper() { }
///
/// This method is used to attach array of SqlCeParameters to a SqlCeCommand.
///
/// This method will assign a value of DbNull to any parameter with a direction of
/// InputOutput and a value of null.
///
/// This behavior will prevent default values from being used, but
/// this will be the less common case than an intended pure output pa
相关文档:
连接ACCESS数据库的简单JSP代码:
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.sql.*" %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String url="jdbc:odbc:Driver={MicroSoft Access Drive ......
接上面的一篇。
方法2:
创建一个单文档应用程序 -> 下一步 -> 选择 Database view without file support ,
单击 Data Source 在弹出的 "数据连接属性" 对话框中,选择 " Microsoft Jet 4.0 OLE DB Provider " 。
单击 下一步 在"选择或输入数据库名称 中,选择 数据库文件所在的路径。同第一篇所述方法,使用默 ......
Access SQL注入参考
版本 0.2.1
(最近更新 10/10/2007)
原作者不详
描述 SQL查询及注释
注释符 Access中没有专门的注释符号.因此"/*", "--"和"#"都没法使用.但是可以使用空字符"NULL"(%00)代替:
' UNION SELECT 1,1,1 from validTableName%00
语法错误信息 "[Microsoft][Driver ODBC Micros ......
1.Asc
说明:返回字母的Acsii值
举例:select Asc("A")返回65
2.Chr
说明:将ascii值转换到字符
举例:select chr(65)返回"A"
3.Format
说明:格式化字符串
举例:Select Format(now(),"yyyy-mm-dd")返回类似于"2008-04-03"
&n ......
<!--#include file="config.asp" -->
<!--#include file="Fun.asp" -->
<%
'数据库管理类
class Datas
'备份
public sub Bk()
Set fso=server.createobject("scripting.filesystemobject")
fso.CopyFile Server.MapPath(SiteDataPath),Server.MapPath(SiteDataBakPath)
......