TCP/IP connexion failed in csharp smart device
-
Hi Eddy, Thanks a lot for u collaboration :).I understand u meaning.I make changement but still not working. My new code is like that:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT \* FROM D°\_urgence"; SqlCommand comm = new SqlCommand(sSQL, new SqlConnection(sConnection)); SqlDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
In fact,my combobox should contain the result of my select statement,but when running,the system is show an sqlexception and nothing is added to my combobox. Is the IPadress the problem?the ipconfig command returns to me this:
C:\Users\Admin>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : Admin-PC
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : NoWireless LAN adapter Wireless Network Connection 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
Physical Address. . . . . . . . . : 06-1B-9E-4A-A0-8C
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesWireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Atheros AR5007EG Wireless Network AdapterHi Calla, Eddy suggests that i change sqlcecommand to sqlcommand because I use .mdf database. Or i don't know maybe i am not understanding what he said :laugh: Thanks
-
Hi, I develop a GMAO csharp smart device application.I try now to connect to my remote database.mdf using TCP/IP protocol.I created a combobox where i want to extract informations from my table using this select statement:
"SELECT DISTINCT NObt FROM 4BT ";
.For my IPadreess of my computer,I use the ipconfig/all command and I take the
IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
My hole code is like this:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT NObt FROM 4BT"; SqlCeCommand comm = new SqlCeCommand(sSQL, new SqlCeConnection(sConnection)); SqlCeDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
When running,this error appears:
Unknown connection option in connection string: initial catalog.
As an information,I follow the steps of this link:http://netcf2.blogspot.com/2005/12/accessing-sql-server-express-from.html[^] What is the problem??? Thank u for all u suggestion Regards Marwen :)
don't use
catch (Exception ex) { MessageBox.Show(ex.Message); }
as it may hide a lot of useful information. Instead use
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
at least as long as it is not working properly all the time. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
don't use
catch (Exception ex) { MessageBox.Show(ex.Message); }
as it may hide a lot of useful information. Instead use
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
at least as long as it is not working properly all the time. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
Hi Luc, I made the changement u ask but the exception still.I wanna clarify that I wanna connect to my database .mdf and not .sdf.Something still not clear in my mind why should i use .mdf database or I work a mobile application so .sdf database required??,:mad: Thanks for u contribution :((
-
Hi Luc, I made the changement u ask but the exception still.I wanna clarify that I wanna connect to my database .mdf and not .sdf.Something still not clear in my mind why should i use .mdf database or I work a mobile application so .sdf database required??,:mad: Thanks for u contribution :((
Tunisien86 wrote:
but the exception still
what did you expect? it does not make the exception go away, it makes you get more information from it, so you have a better chance at understanding what goes wrong and where. X|
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Prolific encyclopedia fixture proof-reader browser patron addict?
We all depend on the beast below.
-
Hi, I develop a GMAO csharp smart device application.I try now to connect to my remote database.mdf using TCP/IP protocol.I created a combobox where i want to extract informations from my table using this select statement:
"SELECT DISTINCT NObt FROM 4BT ";
.For my IPadreess of my computer,I use the ipconfig/all command and I take the
IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
My hole code is like this:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT NObt FROM 4BT"; SqlCeCommand comm = new SqlCeCommand(sSQL, new SqlCeConnection(sConnection)); SqlCeDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
When running,this error appears:
Unknown connection option in connection string: initial catalog.
As an information,I follow the steps of this link:http://netcf2.blogspot.com/2005/12/accessing-sql-server-express-from.html[^] What is the problem??? Thank u for all u suggestion Regards Marwen :)
Is the remote instance really 192.168.1.4 or is it 192.168.1.4\SQLExpress? By default SQLExpress databases run under a SQLExpress instance, and this is what you need to connect to.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi Eddy, Thanks a lot for u collaboration :).I understand u meaning.I make changement but still not working. My new code is like that:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT \* FROM D°\_urgence"; SqlCommand comm = new SqlCommand(sSQL, new SqlConnection(sConnection)); SqlDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
In fact,my combobox should contain the result of my select statement,but when running,the system is show an sqlexception and nothing is added to my combobox. Is the IPadress the problem?the ipconfig command returns to me this:
C:\Users\Admin>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : Admin-PC
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : NoWireless LAN adapter Wireless Network Connection 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
Physical Address. . . . . . . . . : 06-1B-9E-4A-A0-8C
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesWireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Atheros AR5007EG Wireless Network AdapterYou'll have to check 1) Do you have network connectivity on your emulator: start Internet explorer on the emulator, and try to access a well known website (www.codeproject.com). 2) Is your firewall open on port 1433? Also, which exception are you getting now? we need the full text of the exception, which you should now have, if you followed Luc Pattyns' code.
-
Is the remote instance really 192.168.1.4 or is it 192.168.1.4\SQLExpress? By default SQLExpress databases run under a SQLExpress instance, and this is what you need to connect to.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Hello, I have an sql server 2005 standart Edition and not express.A snapshot of my sqlexception is available at this link http://yfrog.com/iycaptureawj[^] Thanks
-
Is the remote instance really 192.168.1.4 or is it 192.168.1.4\SQLExpress? By default SQLExpress databases run under a SQLExpress instance, and this is what you need to connect to.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
If I follow the code in the article he refers to, he would have dumped the instance browser, and locked SqlExpress to port 1433.
-
Hello, I have an sql server 2005 standart Edition and not express.A snapshot of my sqlexception is available at this link http://yfrog.com/iycaptureawj[^] Thanks
Ah the joy of developing for mobile! X| We can't read the full exception (your screen is too small). Put a breakpoint at the exception statement, and examine the 'ex' variable when the expression occurs.
-
You'll have to check 1) Do you have network connectivity on your emulator: start Internet explorer on the emulator, and try to access a well known website (www.codeproject.com). 2) Is your firewall open on port 1433? Also, which exception are you getting now? we need the full text of the exception, which you should now have, if you followed Luc Pattyns' code.
Hi Micheal, As a reponse of u suggestions: 1)my emulator doesn't have network connectivity. 2)how can i know that my firewall is open on port 1433? 3)the sqlexception I got :http://yfrog.com/iycaptureawj[^] Thanks :)
-
Hi Eddy, Thanks a lot for u collaboration :).I understand u meaning.I make changement but still not working. My new code is like that:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT \* FROM D°\_urgence"; SqlCommand comm = new SqlCommand(sSQL, new SqlConnection(sConnection)); SqlDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
In fact,my combobox should contain the result of my select statement,but when running,the system is show an sqlexception and nothing is added to my combobox. Is the IPadress the problem?the ipconfig command returns to me this:
C:\Users\Admin>ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : Admin-PC
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : NoWireless LAN adapter Wireless Network Connection 2:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter
Physical Address. . . . . . . . . : 06-1B-9E-4A-A0-8C
DHCP Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : YesWireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Atheros AR5007EG Wireless Network AdapterTunisien86 wrote:
In fact,my combobox should contain the result of my select statement,but when running,the system is show an sqlexception and nothing is added to my combobox.
It's easier to find a problem if you include the message of the exception. In this case it's probably caused by a common error - your tablenames contain illegal characters. You can "fix" it with brackets;
string sSQL = "SELECT DISTINCT * FROM [D°_urgence]";
Also note that the change in code assumes that your select-statement is run against an SQL Server instance, one that has access to the *.mdf-file that you want to read from. If this data is stored locally, in an *.sdf file, then you'd indeed need the
SqlCe
-classes.Tunisien86 wrote:
Or should I take the physical @ as the @ of my computer?
Ideally, you take the computers' name and the instance name and put it in a configurationfile. Something like "Admin-PC/MySql2005Instance". There might be lots of IP-adresses on a computer, but it usually only has a single name that identifies it in the network. It also communicates easier, imagine yelling "Reboot Skynet and Idefix" in contract to "Reboot One-Nine-Two Doht One-Six-Eight Doht One Doht Zero.. - No Four, I meant Four!" :cool:
I are Troll :suss:
-
Hi, I develop a GMAO csharp smart device application.I try now to connect to my remote database.mdf using TCP/IP protocol.I created a combobox where i want to extract informations from my table using this select statement:
"SELECT DISTINCT NObt FROM 4BT ";
.For my IPadreess of my computer,I use the ipconfig/all command and I take the
IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)
My hole code is like this:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}private void comboBox1\_SelectedIndexChanged(object sender, EventArgs e) { } private void Form6\_Load(object sender, EventArgs e) { string sConnection = "Data Source=192.168.1.4,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;"; string sSQL = "SELECT DISTINCT NObt FROM 4BT"; SqlCeCommand comm = new SqlCeCommand(sSQL, new SqlCeConnection(sConnection)); SqlCeDataReader dr = null; try { comm.Connection.Open(); dr = comm.ExecuteReader(); while (dr.Read()) comboBox1.Items.Add(dr\[0\]); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } dr.Close(); comm.Connection.Close(); } }
}
When running,this error appears:
Unknown connection option in connection string: initial catalog.
As an information,I follow the steps of this link:http://netcf2.blogspot.com/2005/12/accessing-sql-server-express-from.html[^] What is the problem??? Thank u for all u suggestion Regards Marwen :)
Try changing your connection string to
Data Source=192.168.1.4,1433;Network Library=DBMSSOCN;Initial Catalog=GMAO;User ID=sa;Password=sa
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi Micheal, As a reponse of u suggestions: 1)my emulator doesn't have network connectivity. 2)how can i know that my firewall is open on port 1433? 3)the sqlexception I got :http://yfrog.com/iycaptureawj[^] Thanks :)
Tunisien86 wrote:
the sqlexception I got :http://yfrog.com/iycaptureawj\[^\]
Yeah, that one we've already seen. try to get the full exception ON THE PC (see my other reply about this)
Tunisien86 wrote:
my emulator doesn't have network connectivity.
Well, there you have it. No point in testing the others until you can establish that. 1) Is your emulator cradled? 2) do you see the connection in Mobile device center or in ActiveSync?
-
Tunisien86 wrote:
In fact,my combobox should contain the result of my select statement,but when running,the system is show an sqlexception and nothing is added to my combobox.
It's easier to find a problem if you include the message of the exception. In this case it's probably caused by a common error - your tablenames contain illegal characters. You can "fix" it with brackets;
string sSQL = "SELECT DISTINCT * FROM [D°_urgence]";
Also note that the change in code assumes that your select-statement is run against an SQL Server instance, one that has access to the *.mdf-file that you want to read from. If this data is stored locally, in an *.sdf file, then you'd indeed need the
SqlCe
-classes.Tunisien86 wrote:
Or should I take the physical @ as the @ of my computer?
Ideally, you take the computers' name and the instance name and put it in a configurationfile. Something like "Admin-PC/MySql2005Instance". There might be lots of IP-adresses on a computer, but it usually only has a single name that identifies it in the network. It also communicates easier, imagine yelling "Reboot Skynet and Idefix" in contract to "Reboot One-Nine-Two Doht One-Six-Eight Doht One Doht Zero.. - No Four, I meant Four!" :cool:
I are Troll :suss:
Hi Eddy, I wanna clarify something.The database I would connect to is the database of the society I work in.As u know,maintenance societies try try to make easy its work:a technician uses the PDA to connect to the database of the society and finishs his work.The "big" database is a .mdf file.Something was not clear how can i connect to .mdf databse while i should connect to .sdf fine because I develop a mobile application??Is that possible Also about the ip@,is it true what i did?I don't understand u statement really :) is it a problem of Firewall???? Thanks
-
Try changing your connection string to
Data Source=192.168.1.4,1433;Network Library=DBMSSOCN;Initial Catalog=GMAO;User ID=sa;Password=sa
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Hi Pete, I changed but the sqlexception still:
Unknown connection option in connection string: network library.
thanks
-
Ah the joy of developing for mobile! X| We can't read the full exception (your screen is too small). Put a breakpoint at the exception statement, and examine the 'ex' variable when the expression occurs.
Hi Michel, when running the exception is :
NULLREFERENCEEXCEPTION IS UNHANDLED
Null ReferenceExceptionand it point to this statement of my code:
dr.Close();
Thanks
-
Hi Michel, when running the exception is :
NULLREFERENCEEXCEPTION IS UNHANDLED
Null ReferenceExceptionand it point to this statement of my code:
dr.Close();
Thanks
No, that's another exception. It happens because your try block never executed succesfully. put a breakpoint at MessageBox.Show(ex.Message); and look at the value of ex then (with the debugger)
-
Tunisien86 wrote:
the sqlexception I got :http://yfrog.com/iycaptureawj\[^\]
Yeah, that one we've already seen. try to get the full exception ON THE PC (see my other reply about this)
Tunisien86 wrote:
my emulator doesn't have network connectivity.
Well, there you have it. No point in testing the others until you can establish that. 1) Is your emulator cradled? 2) do you see the connection in Mobile device center or in ActiveSync?
Hi Michel, My emulator is not cradling.When googling,I found this link talking about how to cradle an emulator:http://netcf2.blogspot.com/2005/11/getting-started-using-emulator.html[^] I wanna ask should I use a real PDA?is the emulator enough? Thanks
-
No, that's another exception. It happens because your try block never executed succesfully. put a breakpoint at MessageBox.Show(ex.Message); and look at the value of ex then (with the debugger)
Hi Michel, The same appears as i wrote last time,same exception expression thanks
-
Hi Michel, My emulator is not cradling.When googling,I found this link talking about how to cradle an emulator:http://netcf2.blogspot.com/2005/11/getting-started-using-emulator.html[^] I wanna ask should I use a real PDA?is the emulator enough? Thanks
You should cradle it. cradling will give the emulator an IP address. In mobile device center, be sure to select 'DMA' in connection settings. Then do the internet explorer test again.