Hi all, im getting started on Windows mobile, i have worked with win forms
What im trying to do is:
Connect to sql 2000 server on my desktop pc from my mobile device
(emulator), populate a dataset and then save it as an xml file in my mobile
device to work with it offline. (I dont want to install sql mobile on the
device)
I have a code to connect to sql and populate a datatable wich is not working
from my mobile app, but IT WORKS ON WIN FORMS


Dim T As New DataTable("Alumnos")
'For the Data Source Ive tried: PCName and 127.0.0.1 (All of them work with
win forms but not with mobile app)
Dim conn As New SqlConnection("Data Source=127.0.0.1,1433;Initial
Catalog=alumnos;Integrated Security=True")
Dim da As New SqlDataAdapter("Select * from Alumnos", conn)
Try
conn.Open()
da.Fill(T)
Catch ex As SqlException
MsgBox(ex.ToString)
Finally
conn.Close()
End Try


The error i get is: "SQl server does not exist or access denied"
As I told you, the server exist and i get acces from Win Forms code

Ive read that some people who has had this problem was because they were not
using the ip address, ive havent been able to connect
Any suggestions?? Do i have to set iny parameters on the emulator??
I know my emulator is cradled and i still get an error


Alexei Rodriguez

Re: Connecting to SQL 2000 from Mobile App by William

William
Thu Oct 19 12:21:17 CDT 2006

The following code connects my Pocket PC Mobile 5.0 device to SQLExpress on
my desktop computer when it is in the cradle and I run debug and deploy to
the device. Of course, you will end up with the items mentioned in the
needed references on the device, which I think you did not want to do.

Public Class Form1
'note need a reference to system.data, system.data.sqlclient and
system.xml
Dim MyConnection As New System.Data.SqlClient.SqlConnection
Dim MyAdapter As System.Data.SqlClient.SqlDataAdapter
Protected ds As New System.Data.DataSet
Protected cb As System.Data.SqlClient.SqlCommandBuilder

Private Sub MenuItemLoadData_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MenuItemLoadData.Click
MyConnection.ConnectionString = "Data
Source=ComputerName\sqlexpress;Initial Catalog=YOurTable;User Id=YourID;
Password=Passsword"
MyAdapter = New System.Data.SqlClient.SqlDataAdapter("Select * from
Messages", MyConnection)
MyAdapter.Fill(ds)
cb = New System.Data.SqlClient.SqlCommandBuilder(MyAdapter) 'in case
we want to do any inserts, deletions, etc.
'MsgBox(ds.Tables(0).Rows.Count.ToString)
Me.DataGrid1.DataSource = ds.Tables(0)
End Sub

End Class


"Alexei Rodriguez" <Alexei Rodriguez@discussions.microsoft.com> wrote in
message news:93C65124-A2C2-4F31-89E3-0E7B0782849C@microsoft.com...
> Hi all, im getting started on Windows mobile, i have worked with win forms
> What im trying to do is:
> Connect to sql 2000 server on my desktop pc from my mobile device
> (emulator), populate a dataset and then save it as an xml file in my
> mobile
> device to work with it offline. (I dont want to install sql mobile on the
> device)
> I have a code to connect to sql and populate a datatable wich is not
> working
> from my mobile app, but IT WORKS ON WIN FORMS
>
>
> Dim T As New DataTable("Alumnos")
> 'For the Data Source Ive tried: PCName and 127.0.0.1 (All of them work
> with
> win forms but not with mobile app)
> Dim conn As New SqlConnection("Data Source=127.0.0.1,1433;Initial
> Catalog=alumnos;Integrated Security=True")
> Dim da As New SqlDataAdapter("Select * from Alumnos", conn)
> Try
> conn.Open()
> da.Fill(T)
> Catch ex As SqlException
> MsgBox(ex.ToString)
> Finally
> conn.Close()
> End Try
>
>
> The error i get is: "SQl server does not exist or access denied"
> As I told you, the server exist and i get acces from Win Forms code
>
> Ive read that some people who has had this problem was because they were
> not
> using the ip address, ive havent been able to connect
> Any suggestions?? Do i have to set iny parameters on the emulator??
> I know my emulator is cradled and i still get an error
>
>
> Alexei Rodriguez
>



Re: Connecting to SQL 2000 from Mobile App by AlexeiRodriguez

AlexeiRodriguez
Mon Oct 23 16:19:02 CDT 2006

Hi William, thanks for your reply

I havent been able to add a user on sql express (I dont know how, i dont
have any sql manager for this version and i havent found it for download) so
i cant try the example you gave me, but i did something very similar to try
to connect to sql 2000.
Im just tring to open a connection:

Dim conn As New SqlConnection("Server=10.1.0.254,1433;Initial
Catalog=Alumnos;User ID=Alexei;Password=a;Integrated Security=SSPI;")
conn.Open()

Now im getting a different error: General network error. Check your network
documentation
I have tried for Server (in the conn string) the folloing and none of them
work with WM but they do on Win Forms: 10.1.0.254 as well as PCName
As i said befor, i know my emulator is craddled, I also did some testing
with WebServices and after a few tries a was able to consume them
Any other suggestions to connect to sql??
Thank you



"William LaMartin" wrote:

> The following code connects my Pocket PC Mobile 5.0 device to SQLExpress on
> my desktop computer when it is in the cradle and I run debug and deploy to
> the device. Of course, you will end up with the items mentioned in the
> needed references on the device, which I think you did not want to do.
>
> Public Class Form1
> 'note need a reference to system.data, system.data.sqlclient and
> system.xml
> Dim MyConnection As New System.Data.SqlClient.SqlConnection
> Dim MyAdapter As System.Data.SqlClient.SqlDataAdapter
> Protected ds As New System.Data.DataSet
> Protected cb As System.Data.SqlClient.SqlCommandBuilder
>
> Private Sub MenuItemLoadData_Click(ByVal sender As System.Object, ByVal
> e As System.EventArgs) Handles MenuItemLoadData.Click
> MyConnection.ConnectionString = "Data
> Source=ComputerName\sqlexpress;Initial Catalog=YOurTable;User Id=YourID;
> Password=Passsword"
> MyAdapter = New System.Data.SqlClient.SqlDataAdapter("Select * from
> Messages", MyConnection)
> MyAdapter.Fill(ds)
> cb = New System.Data.SqlClient.SqlCommandBuilder(MyAdapter) 'in case
> we want to do any inserts, deletions, etc.
> 'MsgBox(ds.Tables(0).Rows.Count.ToString)
> Me.DataGrid1.DataSource = ds.Tables(0)
> End Sub
>
> End Class

Re: Connecting to SQL 2000 from Mobile App by AlexeiRodriguez

AlexeiRodriguez
Mon Oct 23 16:22:02 CDT 2006

Hi William, thanks for your reply

I havent been able to add a user on sql express (I dont know how, i dont
have any sql manager for this version and i havent found it for download) so
i cant try the example you gave me, but i did something very similar to try
to connect to sql 2000.
Im just tring to open a connection:

Dim conn As New SqlConnection("Server=10.1.0.254,1433;Initial
Catalog=Alumnos;User ID=Alexei;Password=a;Integrated Security=SSPI;")
conn.Open()

Now im getting a different error: General network error. Check your network
documentation
I have tried for Server (in the conn string) the folloing and none of them
work with WM but they do on Win Forms: 10.1.0.254 as well as PCName
As i said befor, i know my emulator is craddled, I also did some testing
with WebServices and after a few tries a was able to consume them
Any other suggestions to connect to sql??
Thank you



"William LaMartin" wrote:

> The following code connects my Pocket PC Mobile 5.0 device to SQLExpress on
> my desktop computer when it is in the cradle and I run debug and deploy to
> the device. Of course, you will end up with the items mentioned in the
> needed references on the device, which I think you did not want to do.
>
> Public Class Form1
> 'note need a reference to system.data, system.data.sqlclient and
> system.xml
> Dim MyConnection As New System.Data.SqlClient.SqlConnection
> Dim MyAdapter As System.Data.SqlClient.SqlDataAdapter
> Protected ds As New System.Data.DataSet
> Protected cb As System.Data.SqlClient.SqlCommandBuilder
>
> Private Sub MenuItemLoadData_Click(ByVal sender As System.Object, ByVal
> e As System.EventArgs) Handles MenuItemLoadData.Click
> MyConnection.ConnectionString = "Data
> Source=ComputerName\sqlexpress;Initial Catalog=YOurTable;User Id=YourID;
> Password=Passsword"
> MyAdapter = New System.Data.SqlClient.SqlDataAdapter("Select * from
> Messages", MyConnection)
> MyAdapter.Fill(ds)
> cb = New System.Data.SqlClient.SqlCommandBuilder(MyAdapter) 'in case
> we want to do any inserts, deletions, etc.
> 'MsgBox(ds.Tables(0).Rows.Count.ToString)
> Me.DataGrid1.DataSource = ds.Tables(0)
> End Sub
>
> End Class