none
connecting to sql server from mobile device

    Question

  • How can I connect to sql server from a mobile device?
    the server is on pc and my app is on the device.
    I want to perform commands and stored procedures which will be performed online on the pc and get immediate results.
    is there any way of achiving that?

    Tuesday, November 15, 2005 11:49 AM

Answers

All replies

  • You will need to add a reference to SQLClient in your project.
    Once this is done its the same as if you were connecting to sqlserver on the full framework with ASP.net or VB.net

    here is some sample code



    Imports System.Data.Common
    Imports System.Data.SqlClient

    Private m_connString As String = "user id=sa;password=;initial catalog=Northwind;Server=xxx.xxx.xxx.xxx;"
    Private m_ds As New DataSet

    Dim l_sqlConn As SqlConnection
            Dim l_da As DataAdapter
            Dim l_ds As DataSet
            Dim l_sqlStmt As String
            Try
                l_sqlConn = New SqlConnection(m_connString)
                l_sqlConn.Open()

                l_sqlStmt = "SELECT * FROM tbl_Users ORDER BY FullName"
                l_da = New SqlDataAdapter(l_sqlStmt, l_sqlConn)
                m_ds = New DataSet
                l_da.Fill(m_ds)


            Catch ex As SqlException
                Dim l_sqlerr As SqlError
                For Each l_sqlerr In ex.Errors
                    MsgBox(l_sqlerr.Message)
                Next
            Finally
                If l_sqlConn.State = ConnectionState.Open Then
                    l_sqlConn.Close()
                    l_sqlConn = Nothing
                End If
            End Try

    Dim l_cmd As SqlCommand = l_sqlConn.CreateCommand()
    l_cmd.CommandType = CommandType.StoredProcedure
    l_cmd.CommandText = "<Stored Procedure Name>"

     l_cmd.Parameters.Add(New SqlParameter("UnitOutDate", SqlDbType.DateTime))
            l_cmd.Parameters("UnitOutDate").Value = Date.Now

    l_cmd.executeNonQuery()

     

    Tuesday, November 15, 2005 11:58 AM
  • It's all good and pretty except for one little thing:
    when i try to open the connection i get a "PlatformNotSupportedException"
    is there any reason that exception could appears?
    Thursday, November 24, 2005 11:43 AM
  • on the emulator or on the device
    Thursday, November 24, 2005 12:12 PM
  • let me specify a little:
    I have a device which has a microsoft windows ce .net version 4.2 system.
    i try to connect it to sqlserver 2000 that is on a pc server(win 2000 for servers). I create SqlConnect object on the device with the connection string
    "Persist Security Info=False;Integrated Security=false; database=northwind; server=xxx.xxx.xxx.xxx; Connect Timeout=30; User ID=testing; Password=test;"
    so far so good, but when i perform the function Open(on the device itself), I get the "PlatformNotSupportedException".
    and i just cannot figure out why.

    Thursday, November 24, 2005 12:23 PM
  • hmmm it sounds as if something is missing on the device like a library.
    Try testing it on the emulator and see if you get the same error

    Thursday, November 24, 2005 3:03 PM
  • That usually means DB collation you're using is not supported on particular device. You can change collation of this DB or get localized device which supports locale you’re using.

    Thursday, November 24, 2005 5:42 PM
  • You hit the correct spot, it really is DB collation.
    I created another database on the same server and gave it's collation Latin1_General_CI_AS and tried again and it worked :-)

    which brings me to this question:
    is there any way to tell the connection object what the database collation is? because I dont think i'm allowed to convert the database to Latin1_General_CI_AS collation.
    or any other way to solve this mess...
    Sunday, November 27, 2005 9:57 AM
  • you can specify the locale identifier in the connection string.
    see:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlservercesqlceconnectionclassconnectionstringtopic.asp

    -Darren Shaffer
    .NET Compact Framework MVP
    Thursday, December 01, 2005 11:17 PM
  •  Darren Shaffer wrote:
    you can specify the locale identifier in the connection string.
    see:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlservercesqlceconnectionclassconnectionstringtopic.asp

    -Darren Shaffer
    .NET Compact Framework MVP


    I have this same problem (platformnotsupported) and I don't understand your answer. Problem is with SqlConnection and you say that we must add locale identifier in connection string to SqlCeConnection??
    Sunday, April 15, 2007 5:39 PM
  • As you correctly noted this is not going to work with SQL Client as it’s about SQL CE. So you have two choices:

     

    1. Change database collation to something which is supported on device.

    2. Get device which supports your database collation.

     

    Sunday, April 15, 2007 5:52 PM
  •  Ilya Tumanov wrote:

    As you correctly noted this is not going to work with SQL Client as it’s about SQL CE. So you have two choices:

    1. Change database collation to something which is supported on device.

    2. Get device which supports your database collation.



    I know Smile
    Ad 1. No, i can't change collation of my database.
    Ad.2. I can't get device which support my database collation (it is Symbol MC9090 with Win CE 5.0 and my database have Polish_CI_AS collation). Works great when I change colllation to Latin1_general but i can't do this with my main database.

    Is there an other option? I try RDA but problem with charsets exists, Polish chars ą ś ć ń etc. changes to strange symbols, its useless.
    Sunday, April 15, 2007 6:28 PM
  • i want to connect my device which is gprs enabled to a server  via gprs .. so what should be the coding in Asp.net on the server that i should do.. Plz help me i have to submit this project but i m not finding a suitable answer
    Friday, July 22, 2011 6:40 AM