Results 1 to 26 of 26

Thread: [RESOLVED] want to connect to sql server using mobile application

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Resolved [RESOLVED] want to connect to sql server using mobile application

    i am newbie to world of mobile application.
    i have vs2005. i want to develop vs2005 mobile application for windows phone which connect to sql server which i have on server and connect to it and display some data depending on query.

    can any one let me know how to start.i want to this using code. not any data-source. can anyone help me out what to do???
    i think just first need to know how to connect to sql server in mobile device application.

    i know this is silly question but not for me.

    waiting for your reply .

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    Are you wanting to be able to have a database on the device, i.e. for when the application is being used off-line, or are you wanting to be to connect to a full blown SQL Instance when the mobile device is docked to a PC.

    The two situations are very different.

    One thing you could do is this:

    Use SQL Server Compact Edition:

    http://www.microsoft.com/Sqlserver/2...s/compact.aspx

    On the device, that will give you a full relational database on the device. You can then use Merge Replication on the device to synchronize changes back to a full blown SQL Server Instance.

    Gary

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    HI SIR,
    firstly thank you so much for your quick reply.

    regarding your reply.
    no i dont want to have database on my mobile device, my application is just like client sending request to sql server which is at remote place and get result from sql server depending on sql query.

    here is what exactly i want to do, i want to connect to sql server which is remote at remote place. its same like windows application which connect remote sql server so that i can execute query on it and have result.

    again no database on mobile device.
    waiting for your reply.

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    Hi,
    use the SqlClient namespace and just connect to your server, and issue commands as you would with a windows forms application.

    If you search this forum, there are examples of connection strings etc.

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Which connection are you using from the Mobile Device?

    Wifi, GPRS?!?

    You are going to need to connect as Pete has suggested. Have a look at:

    http://www.connectionstrings.com/

    For getting the correct connection string.

    Gary

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    i have correct connetion string.
    but where i try imports system.data.sqlclient and declare sqlconnetion variable.
    i get this error
    Code:
    Error	1	Reference required to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes' containing the implemented interface 'System.Data.IDbConnection'.
    .

    i already have reference to this file in project but version is 3.5. i dont see version 2.0 in my reference.

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: want to connect to sql server using mobile application

    I don't think the full SQLClient is available in the Compact Framework... but I'm not 100% sure about that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    There is an article here about configuring VS2005 to work with later versions of SQL CE - it may help you
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  9. #9
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by techgnome View Post
    I don't think the full SQLClient is available in the Compact Framework... but I'm not 100% sure about that.

    -tg
    Yes - SQLClient is available for mobile development - we have a few things missing, but SQL access is not one of them
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    so any there is no way to connect to my remote sql server from mobile???

  11. #11
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by bhavin12300 View Post
    so any there is no way to connect to my remote sql server from mobile???
    Yes - SQLClient works - I have used it in several applications.

    With the right references and connection string, it is no different than accessing SQLServer from a windows forms application.
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    I sense an example is needed....

    A quick google turned up this:

    http://www.devbuzz.com/Articles/zinc...erver_pg1.aspx

    Is that by you Pete?

    Gary

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by petevick View Post
    Yes - SQLClient works - I have used it in several applications.

    With the right references and connection string, it is no different than accessing SQLServer from a windows forms application.
    but sir i get following error when i add reference to system.data.sqlclient.

    Reference required to assembly 'System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes' containing the implemented interface 'System.Data.IDbConnection'.

    am i doing anything wrong???

  14. #14
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    Can you explain the exact steps you have taken to arrive at this error?

    Have you added a reference to the System.Data assembly?

    Try following the steps in the article that I linked to.

    Gary

  15. #15
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    Are you adding a 'desktop' version of the system.data??

    Yes Gary - the article is by me

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  16. #16
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by petevick View Post
    Yes Gary - the article is by me
    Ha ha, that's quite funny!! What are the chances that the first article I would find on this topic would be written by you

    Gary

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by petevick View Post
    Are you adding a 'desktop' version of the system.data??

    Yes Gary - the article is by me

    Pete
    first my system.data.sqlclient is C:\Program Files\Microsoft SQL Server Compact Edition\v3.5\Devices\Client\System.Data.SqlClient.dll

    and system.data is
    C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\WindowsCE\System.Data.dll


    hi thanks for that article.
    but i am getting following error while try to connect to my local sql server.
    SAI\SQLEXPRESS server not found.

    my connection string is this. it perfectly worked in windows application.
    server=SAI\SQLEXPRESS;Integrated Security=true;Database=shopbot

  18. #18
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    It is unlikely that your device is going to be able to resolve the name of your server, i.e. SAI. You are going to need to give it an IP Address to connect to, and also, unless the device is connected to the domain, you are going to need to give it a user name and password in the connection string to connect to the database with.

    Gary

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    Quote Originally Posted by gep13 View Post
    Hey,

    It is unlikely that your device is going to be able to resolve the name of your server, i.e. SAI. You are going to need to give it an IP Address to connect to, and also, unless the device is connected to the domain, you are going to need to give it a user name and password in the connection string to connect to the database with.

    Gary
    i changed ip address to this placing ip adreess.
    "server=127.0.0.1;Integrated Security=True;Database=shopbot;"
    now getting error like this.
    server does not exist or access denied.

  20. #20
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: want to connect to sql server using mobile application

    127.0.0.1 -- isn't that the loopback address? In other words, that's the same as doing "local" for the server... which means it's looking at the device, not the server.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  21. #21
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    Yip, 127.0.0.1 is the equivalent of localhost, i.e. itself.

    You have said already that you are trying to connect to a remote server, so this IP address is certainly not it.

    Do you know the IP address of the server? If not, you should be able to get it by opening up a command prompt and typing:

    Code:
    ping SAI
    Also, it doesn't look like you have modified the connection string to include an authorized user name and password. You are going to need to do this before the connection will work.

    Have you read the article? This topic is discussed in detail at the bottom half of the first page.

    Gary

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    i think problem is in my emulator is not connected to internet.
    coz when i use following code just to get webpage it gives me error that "Could not establish connection to network."
    Code:
    Dim web1 As System.Net.HttpWebRequest
            Dim html As String
            web1 = System.Net.WebRequest.Create("http://www.google.com")
            Dim response5 As HttpWebResponse = web1.GetResponse
            Dim reader2 As StreamReader = New StreamReader(response5.GetResponseStream, System.Text.Encoding.GetEncoding(1252))
    
            Try
                html = reader2.ReadToEnd
                response5.Close()
                reader2.Close()
            Catch ex As Exception
            End Try

  23. #23
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: want to connect to sql server using mobile application

    Hi,
    there are many discussions (and solutions) on the forum about connecting to SQL Express - bottom line is you need the IP address.

    I would also test against a server on your network before being brave enought to test it on the internet. You will need to cradle your device emulator.

    In Visual Studio, when the emulator is running, click on Tools>Device Emulator Manager.

    Scroll down the list, looking for your emulator (which should show as connected), right-click on it, and choose cradle. This should connect the device using activesync (or WMDC), and you should be able to access the internet. If you have problems connecting, make sure activesync allow connections to DMA
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  24. #24
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    Here is some guidance on cradling the emulator:

    http://windowsmobilepro.blogspot.com...3-quickly.html

    Gary

  25. #25

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    91

    Re: want to connect to sql server using mobile application

    hi,
    its working now.
    i installed active sync 4.5 and virtual pc and now its succesfully connecting to internet .

    thank you so much expert . thanks for your really quicky reply.

  26. #26
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: want to connect to sql server using mobile application

    Hey,

    Good stuff, glad to hear that you have got it working.

    Remember to follow the links in my signature to mark your thread as resolved.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width