Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-CE Mobile compact
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);
            }
              
            
        }
    }
}
Posted 13-Mar-13 11:02am
fa.luis270
Comments
richcb at 13-Mar-13 16:15pm
   
DataBase, Server, UID, and PWD are not connection string properties. It is Data Source for the database, Initial Catalog for the server, User ID for user, and Password for password.
Marco Bertschi at 13-Mar-13 17:49pm
   
Can you post the detailed error message?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v3
Comments
kyros88 at 8-Jan-14 6:16am
   
Hello there,
 
I have the same problem, so I am trying this solution you are suggesting! But, there is a problem in "SqlCeConnection".. I see that you are using theses two asseblies
using System.Data.SqlTypes;
using System.Data.SqlServerCe;
 
Where can I found them?
 
I am trying to build a silverlight widows phone application in 7, 7.1
Sandip.Nascar at 8-Jan-14 8:37am
   
have a look at the solution. I have updated the answer. This will give you a right path.
kyros88 at 8-Jan-14 15:46pm
   
ok I see your point! Can I go a little further?
 
I create an ASP.NET Empty Web Application. After that I Add a new item and insert an ADO.NET Entity Model. Generate from database. I used an already created connection (Not New Connection) (Pluralize or signularize generated objects names and include foreign keys.. selected both).
Now, do I have to create again the dabase exaclty as it is in hosting DB? How this will help me to grab the information from the server DB?
 
I saw this tutorial and doing this step by step:
(http://studentguru.gr/b/dt008/archive/2010/12/02/querying-a-database-on-windows-phone-7-using-wcf.aspx?pi127=1#comments)
 
My target is, people who have created an account through my web site, can login to my application. So, I need to grab the username and password (..and more..) from the server DB.
(I am using Visual studio 2010 and windows silverlight app).
Sandip.Nascar at 9-Jan-14 1:31am
   
We have primarily 2 types of application we build in mobile device -
native and web. Another one is a mixture of native and web, we call it hybrid.
 
Now the point is, if you build a web applicatuion, you can connect to sql server through external ip and port.
But if you are trying to build it as native in windows phone, you cannot connect to external ip directly and use ADO.NET. You can connect to local sql CE or connect to external sql server using WCF or web service.
 
Same when you use silverlight. Silverlight cannot use ADO.NET.
kyros88 at 9-Jan-14 10:06am
   
I saw another tut, that say to open a new project in VS2010 and create a Database connection (through the ServerExplorer and click on Connect to a Database) Then a pop up appears. By inserting the Server name, sql server authentication and name of database CAN I connect remotely to my DB?
 
Moreover, there is a choice in this pop-up window that says Microsoft Sql Server(SqlClient) I change that to MysqDatabase, but when I try to write in this form, the form close.. Why is that happening? Am I missing something? (still working inside the silverlight app)
Sandip.Nascar at 9-Jan-14 10:11am
   
You are confusine with silverlight and plain web (ASP.NET).
 
I have told earlier, if you use silverlight, you cannot use ADO.NET.
Silverlight is a plugin, so the only way to talk to external sql server or any database is only with WCF/webservice.
 
For simple web, you can use sql server and ado.net.
kyros88 at 9-Jan-14 11:18am
   
ok..So as I wrote yesterday, by creating an ASP.NET project and adding a Silverlight-enabled WCF Service, can I connect my sql Database? (Am I right until now?). And if I can, how can I do this connection? Do you have any tut or something to read about this ? Should I create inside the WCF a string Connection and so on?..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 8 Jan 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100