Click here to Skip to main content
15,886,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Richard C Bishop 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 13-Mar-13 17:49pm    
Can you post the detailed error message?

1 solution

The connection string looks to be wrong -

Here are some examples which might help you,
C#
//Standard Security
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;

C#
//Connection to SQL Server Instance
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;

For your case, it should be -
C#
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
 
Share this answer
 
v3
Comments
kyros88 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 8-Jan-14 8:37am    
have a look at the solution. I have updated the answer. This will give you a right path.
kyros88 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 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 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)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900