您的位置:首页 > 数据库

.NET Compact Framework在windows ce 5.0上直接访问桌面版的SQL Server 2005

2009-09-03 13:38 465 查看
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-1610611985 1073750139 0 0 159 0;}
@font-face
{font-family:新宋体;
panose-1:2 1 6 9 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:modern;
mso-font-pitch:fixed;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@宋体";
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"/@新宋体";
panose-1:2 1 6 9 3 1 1 1 1 1;
mso-font-charset:134;
mso-generic-font-family:modern;
mso-font-pitch:fixed;
mso-font-signature:3 135135232 16 0 262145 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
mso-themecolor:hyperlink;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-noshow:yes;
mso-style-priority:99;
color:purple;
mso-themecolor:followedhyperlink;
text-decoration:underline;
text-underline:single;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
margin:0cm;
margin-bottom:.0001pt;
text-align:justify;
text-justify:inter-ideograph;
text-indent:21.0pt;
mso-char-indent-count:2.0;
mso-pagination:none;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;}
/* Page Definitions */
@page
{mso-page-border-surround-header:no;
mso-page-border-surround-footer:no;}
@page Section1
{size:595.3pt 841.9pt;
margin:72.0pt 90.0pt 72.0pt 90.0pt;
mso-header-margin:42.55pt;
mso-footer-margin:49.6pt;
mso-paper-source:0;
layout-grid:15.6pt;}
div.Section1
{page:Section1;}
/* List Definitions */
@list l0
{mso-list-id:2127966426;
mso-list-type:hybrid;
mso-list-template-ids:-1625365852 888459414 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
{mso-level-text:%1、;
mso-level-tab-stop:none;
mso-level-number-position:left;
margin-left:18.0pt;
text-indent:-18.0pt;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
-->

.NET Compact Framework

windows ce
5.0
上直接访问桌面版的
SQL Server 2005

参照
http://blog.csdn.net/upto/archive/2007/09/23/1797126.aspx

的提示和外国朋友的劳动成果。本人英文不好不能翻译只能将自己理解总结如下:

环境:

SQL Server 2005 + SQL Server Compcat 3.5
SP1 XP SP3 Virsual Studio 2008

1、

配置
SQL Server
2005
远程连接

开始
->
所有程序
->Microsoft SQL Server 2005->
配置工具
->SQL Server
外围应用配置器
或者

Click On Start | All Programs | Microsoft
SQL Server2005 | Configuration Tools | SQL Server Surface Area configuration



点击

服务和连接的外围应用配置器


Surface Area Configuration for Services and Connections”



按照上面的选项:选择远程连接
->
选择本地连接和远程连接
->
选中同时使用
TCP/IP

named pipes(B)

点击“应用”或者确定即可。重新启动服务。

2、

配置防火墙

开始
->
控制面板
->
安全中心
->Windows
防火墙



点击“添加程序”,选择
C:/Program Files/Microsoft SQL Server/MSSQL.1/MSSQL/Binn/sqlservr.exe
选择确定

3、

编写程序

myConn = new
SqlConnection
(@"Server=192.168.1.189;Database=C_Gather;
User Id=csqlce; Password=CAOchangHONG12345^&*()"
);

myConn.Open();

SqlDataReader
myDataReader;

SqlCommand
myCmd = myConn.CreateCommand();

myCmd.CommandText = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'"
;

treeView1.BeginUpdate();

treeView1.Nodes.Clear();

treeView1.Nodes.Add(new
TreeNode
("Tables"
));

TreeNode
childNode = treeView1.Nodes[0];

int
childCount = 0;

myDataReader =
myCmd.ExecuteReader();

while
(myDataReader.Read())

{

string
TableName = (myDataReader[0].ToString()) + "."
+ (myDataReader[1].ToString());

childNode.Nodes.Insert(childCount, new
TreeNode
(TableName));

childCount += 1;

}

myDataReader.Close();

treeView1.Nodes.Add(new
TreeNode
("Views"
));

SqlCommand
myCmdView = myConn.CreateCommand();

myCmdView.CommandText = @"SELECT TABLE_SCHEMA, TABLE_NAME FROM
INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'VIEW'"
;

TreeNode
childNodeView = treeView1.Nodes[1];

int
childCountView = 0;

myDataReader =
myCmdView.ExecuteReader();

while
(myDataReader.Read())

{

string
ViewName = (myDataReader[0].ToString()) + "."
+ (myDataReader[1].ToString());

childNodeView.Nodes.Insert(childCount,
new
TreeNode
(ViewName));

childCountView += 1;

}

myDataReader.Close();

treeView1.ExpandAll();

treeView1.EndUpdate();

myConn.Close();

} // try

catch
(SqlException
myexception)

{

foreach
(SqlError
err in
myexception.Errors)

{

MessageBox
.Show(err.Message);

}

}

类似上面的代码,你可以到http://www.opennetcf.com/downloads/download.aspx?s=SSMS_Device

下载他的完整代码

运行以后在myConn.Open();
可能出现错误与他dbnetlib.dll
有关的错误。你将
C:/Program
Files/Microsoft SQL Server Compact Edition/v3.5/Devices/Client/wce500/x86
文件夹下两个文件

sql.dev.CHS.wce5.x86.CAB

sql.wce5.x86.CAB
拷贝到目标设备上安装重新运行即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐