如何从Windows Mobile连接到SQL SERVER? [英] How Can I connect to SQL SERVER from windows mobile?

查看:104
本文介绍了如何从Windows Mobile连接到SQL SERVER?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试连接时遇到问题来自visual studio 2005的SQL SERVER我正在为windows mobile 6开发一个应用程序



但是当我运行我的程序时,显示以下错误



连接字符串中的未知连接选项:服务器。



您知道我该如何解决这个问题?我的代码如下:



使用System; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Text;
使用System.Windows.Forms;
使用System.Data.SqlTypes;
使用System.Data.SqlServerCe;


namespace DeviceApplication1
{
public partial class Form1:Form
{
// string strCon =Data Source = 148.232.18.5 ;初始目录= GPODGOATQ;集成安全性= SSPI;用户ID = dbowner;密码= corpdgo; //\"Server=148.232.18.5;UID=dbowner;PWD=corpdgo;DATABASE=GPODGOATQ;
SqlCeConnection conexion = new SqlCeConnection(SERVER = 148.232.18.5; UID = dbowner; PWD = corpdgo; DATABASE = GPODGOATQ);
System.Data.SqlClient.SqlConnection conexon = new System.Data.SqlClient.SqlConnection(Server = 148.232.18.5; UID = dbowner; PWD = corpdgo; DATABASE = GPODGOATQ);
public Form1()



{
InitializeComponent();
}

private void button1_Click(object sender,EventArgs e)
{
//MessageBox.Show(\"Hola Mundo desde Mobile);

DataTable dt = new DataTable();
//System.Data.SqlClient.SqlDataAdapter da2 = new System.Data.SqlClient.SqlDataAdapter(从caljum02中选择fechap,其中FechaP ='20130310'和Rollo IN(19,10)和Maquina = 2,strCon );

System.Data.SqlServerCe.SqlCeDataAdapter da = new System.Data.SqlServerCe.SqlCeDataAdapter(select * from caljum02,其中FechaP ='20130310'和Rollo IN(19,10)和Maquina = 2 ,conexion);



尝试
{

da.Fill(dt);
dataGrid1.DataSource = dt;
}
catch(例外a)

{

MessageBox.Show(+ a);
}


}
}
}

解决方案

< blockquote>连接字符串看起来是错误的 -



以下是一些可能对您有帮助的例子,

  //  标准安全 
Server = myServerAddress; Database = myDataBase; User Id = myUsername;密码= myPassword;



  //  连接到SQL Server实例 
Server = myServerName \ myInstanceName; Database = myDataBase; User Id = myUsername;
密码= myPassword;



对于您的情况,它应该是 -

 SqlCeConnection conexion =  new  SqlCeConnection(  SERVER = 148.232.18.5;用户标识=的dbowner;密码= corpdgo; DATABASE = GPODGOATQ); 
System.Data.SqlClient.SqlConnection conexon = new System.Data.SqlClient.SqlConnection( Server = 148.232.18.5; UID = dbowner; PWD = corpdgo; DATABASE = GPODGOATQ;);





现在从手机(Windows)连接,你不能使用ADO.NET,因为它在silverlight中不可用。

要连接到sql server CE,你可以google(如何从Windows Mobile连接swql服务器CE)

如果要连接到数据库服务器中托管的外部sql服务器,请尝试使用WCF或Web服务编写可以从Windows使用的公共公开方法移动。



希望这会有所帮助。



欢呼


Hello, I have a problem when I try to connect to SQL SERVER from visual studio 2005 I'm developing an application for windows mobile 6

but when I run my program, show the error below

Unknown connection option in connection string: server.

Do you know how can I solve this? my code below:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlTypes;
using System.Data.SqlServerCe;


namespace DeviceApplication1
{
    public partial class Form1 : Form
    {
       // string strCon ="Data Source=148.232.18.5;Initial Catalog=GPODGOATQ;Integrated Security=SSPI;User ID=dbowner;Password=corpdgo"; //"Server=148.232.18.5;UID=dbowner;PWD=corpdgo;DATABASE=GPODGOATQ";
        SqlCeConnection conexion = new SqlCeConnection("SERVER=148.232.18.5;UID=dbowner;PWD=corpdgo;DATABASE=GPODGOATQ");
        System.Data.SqlClient.SqlConnection conexon = new System.Data.SqlClient.SqlConnection("Server=148.232.18.5;UID=dbowner;PWD=corpdgo;DATABASE=GPODGOATQ");
        public Form1()


          
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //MessageBox.Show("Hola Mundo desde Mobile");
            
            DataTable dt = new DataTable();
            //System.Data.SqlClient.SqlDataAdapter da2 = new System.Data.SqlClient.SqlDataAdapter("select fechap from caljum02	where FechaP = '20130310'	and Rollo IN(19,10)	and Maquina = 2", strCon);

            System.Data.SqlServerCe.SqlCeDataAdapter da = new System.Data.SqlServerCe.SqlCeDataAdapter("select * from caljum02	where FechaP = '20130310'	and Rollo IN(19,10)	and Maquina = 2", conexion);
            
      
          
            try
            {

                da.Fill(dt);
                dataGrid1.DataSource = dt;
            }
            catch(Exception a) 
                
            { 
            
            MessageBox.Show(""+a);
            }
              
            
        }
    }
}

解决方案

The connection string looks to be wrong -

Here are some examples which might help you,

//Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;


//Connection to SQL Server Instance
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;


For your case, it should be -

SqlCeConnection conexion = new SqlCeConnection("SERVER=148.232.18.5;User       Id=dbowner;Password=corpdgo;DATABASE=GPODGOATQ");
System.Data.SqlClient.SqlConnection conexon = new   System.Data.SqlClient.SqlConnection("Server=148.232.18.5;UID=dbowner;PWD=corpdgo;DATABASE=GPODGOATQ;");



Now to connect from mobile(Windows), you cannot use ADO.NET as it is unavailable in silverlight.
To connect to sql server CE, you can google (how to connect swql server CE from windows mobile)
If you want to connect to external sql server hosted in database server, try to use WCF or web service to write public exposed methods that you can consume from windows mobile.

Hope this helps.

cheers


这篇关于如何从Windows Mobile连接到SQL SERVER?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆