PDA

Click to See Complete Forum and Search --> : [RESOLVED] want to connect to sql server using mobile application


bhavin12300
Sep 9th, 2009, 03:29 AM
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 .

gep13
Sep 9th, 2009, 04:30 AM
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/2005/en/us/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

bhavin12300
Sep 9th, 2009, 07:03 AM
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.

petevick
Sep 9th, 2009, 07:13 AM
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

gep13
Sep 9th, 2009, 07:37 AM
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

bhavin12300
Sep 9th, 2009, 08:04 AM
i have correct connetion string.
but where i try imports system.data.sqlclient and declare sqlconnetion variable.
i get this error
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.

techgnome
Sep 9th, 2009, 08:30 AM
I don't think the full SQLClient is available in the Compact Framework... but I'm not 100% sure about that.

-tg

petevick
Sep 9th, 2009, 08:31 AM
There is an article here (http://blogs.msdn.com/stevelasker/archive/2007/08/07/configuring-visual-studio-2005-for-use-wtih-sql-server-2005-compact-edition.aspx) about configuring VS2005 to work with later versions of SQL CE - it may help you

petevick
Sep 9th, 2009, 08:41 AM
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 :)

bhavin12300
Sep 9th, 2009, 08:58 AM
so any there is no way to connect to my remote sql server from mobile???

petevick
Sep 9th, 2009, 09:23 AM
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.

gep13
Sep 9th, 2009, 09:46 AM
Hey,

I sense an example is needed....

A quick google turned up this:

http://www.devbuzz.com/Articles/zinc_sqlclient_remote_sql_server_pg1.aspx

Is that by you Pete?

Gary

bhavin12300
Sep 9th, 2009, 10:16 AM
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???

gep13
Sep 9th, 2009, 10:17 AM
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

petevick
Sep 9th, 2009, 10:33 AM
Are you adding a 'desktop' version of the system.data??

Yes Gary - the article is by me :)

Pete

gep13
Sep 9th, 2009, 10:36 AM
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

bhavin12300
Sep 9th, 2009, 12:11 PM
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

gep13
Sep 9th, 2009, 12:16 PM
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

bhavin12300
Sep 9th, 2009, 12:54 PM
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.

techgnome
Sep 9th, 2009, 01:57 PM
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

gep13
Sep 9th, 2009, 03:30 PM
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:


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

bhavin12300
Sep 9th, 2009, 10:46 PM
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."
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

petevick
Sep 10th, 2009, 01:14 AM
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

gep13
Sep 10th, 2009, 02:50 AM
Hey,

Here is some guidance on cradling the emulator:

http://windowsmobilepro.blogspot.com/2006/05/emulator-troubleshootingtip-03-quickly.html

Gary

bhavin12300
Sep 10th, 2009, 06:29 AM
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.

gep13
Sep 10th, 2009, 06:30 AM
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