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

来源:互联网 发布:复杂网络引论 编辑:程序博客网 时间:2024/05/10 16:07

<!-- /* 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 Frameworkwindows ce5.0上直接访问桌面版的SQL Server 2005

 

参照http://blog.csdn.net/upto/archive/2007/09/23/1797126.aspx的提示和外国朋友的劳动成果。本人英文不好不能翻译只能将自己理解总结如下:

 

环境:

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

 

1、  配置SQL Server2005远程连接

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

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

设置图片

点击服务和连接的外围应用配置器 Surface Area Configuration for Services and Connections”

配置图片

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

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

 

2、  配置防火墙

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

 防火墙

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

 

 

3、  编写程序

 

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

                myConn.Open();

                SqlDataReadermyDataReader;

                SqlCommandmyCmd = myConn.CreateCommand();

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

                treeView1.BeginUpdate();

                treeView1.Nodes.Clear();

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

                TreeNodechildNode = treeView1.Nodes[0];

                intchildCount = 0;

                myDataReader =myCmd.ExecuteReader();

                while(myDataReader.Read())

                {

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

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

                    childCount += 1;

                }   

                myDataReader.Close();

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

                SqlCommandmyCmdView = myConn.CreateCommand();

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

                TreeNodechildNodeView = treeView1.Nodes[1];

                intchildCountView = 0;

                myDataReader =myCmdView.ExecuteReader();

                while(myDataReader.Read())

                {

                    stringViewName = (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 inmyexception.Errors)

                {

                    MessageBox.Show(err.Message);

}

}

 

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

 

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

sql.dev.CHS.wce5.x86.CABsql.wce5.x86.CAB拷贝到目标设备上安装重新运行即可。

原创粉丝点击