TCP/IP connexion failed to sql server 2005 database .mdf

  • 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

    My hole code is like this:

    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:

    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 adr = "SELECT @@SERVERNAME AS 'Server Name';";

    string sConnection = "Data Source=Admin-PC,1433;Initial Catalog=GMAO;User ID=sa;Password=sa;";

    string sSQL = "SELECT Nbt FROM 4BT; ";

    SqlConnection conn = new SqlConnection(sConnection);

    SqlCommand comm = new SqlCommand(sSQL, conn);

    SqlDataReader dr = null;

    try

    {

    comm.Connection.Open();

    dr = comm.ExecuteReader();

    while (dr.Read())

    comboBox1.Items.Add(dr[0]);

    }

    catch (SqlException ex)

    {

    MessageBox.Show(ex.Message);

    return;

    }

    dr.Close();

    comm.Connection.Close();

    }

    }

    }

    When trying to know the IP @ that I should write in the dataSource field,I verify the ipconfig command prompt.It returns me like that:

    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. . . . . . . . : No

    Wireless 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 . . . . : Yes

    Wireless LAN adapter Wireless Network Connection:

    Connection-specific DNS Suffix . :

    Description . . . . . . . . . . . : Atheros AR5007EG Wireless Network Adapter

    Physical Address. . . . . . . . . : 00-1B-9E-4A-A0-8C

    DHCP Enabled. . . . . . . . . . . : Yes

    Autoconfiguration Enabled . . . . : Yes

    Link-local IPv6 Address . . . . . : fe80::cc28:8ea3:82ea:4c4f%13(Preferred)

    IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)

    Subnet Mask . . . . . . . . . . . : 255.255.255.0

    Lease Obtained. . . . . . . . . . : mercredi 5 mai 2010 10:08:26

    Lease Expires . . . . . . . . . . : jeudi 6 mai 2010 10:08:25

    Default Gateway . . . . . . . . . : 192.168.1.1

    DHCP Server . . . . . . . . . . . : 192.168.1.1

    DHCPv6 IAID . . . . . . . . . . . : 234888094

    DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-13-55-22-65-00-1A-92-FC-E6-7E

    DNS Servers . . . . . . . . . . . : 192.168.1.1

    192.168.1.1

    NetBIOS over Tcpip. . . . . . . . : Enabled

    Ethernet adapter Local Area Connection:

    Media State . . . . . . . . . . . : Media disconnected

    Connection-specific DNS Suffix . : home

    Description . . . . . . . . . . . : Realtek RTL8139/810x Family Fast Ethernet

    NIC

    Physical Address. . . . . . . . . : 00-1A-92-FC-E6-7E

    DHCP Enabled. . . . . . . . . . . : Yes

    Autoconfiguration Enabled . . . . : Yes

    Tunnel adapter isatap.home:

    Media State . . . . . . . . . . . : Media disconnected

    Connection-specific DNS Suffix . :

    Description . . . . . . . . . . . : Microsoft ISATAP Adapter

    Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

    DHCP Enabled. . . . . . . . . . . : No

    Autoconfiguration Enabled . . . . : Yes

    Tunnel adapter Local Area Connection* 11:

    Connection-specific DNS Suffix . :

    Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter

    Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

    DHCP Enabled. . . . . . . . . . . : No

    Autoconfiguration Enabled . . . . : Yes

    IPv6 Address. . . . . . . . . . . : 2001:0:4137:9e74:454:bc2:3f57:fefb(Prefer

    red)

    Link-local IPv6 Address . . . . . : fe80::454:bc2:3f57:fefb%11(Preferred)

    Default Gateway . . . . . . . . . : ::

    NetBIOS over Tcpip. . . . . . . . : Disabled

    Tunnel adapter isatap.{9CD32A2C-C6BD-42FC-9F45-933E12729451}:

    Media State . . . . . . . . . . . : Media disconnected

    Connection-specific DNS Suffix . :

    Description . . . . . . . . . . . : Microsoft ISATAP Adapter #2

    Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

    DHCP Enabled. . . . . . . . . . . : No

    Autoconfiguration Enabled . . . . : Yes

    Tunnel adapter isatap.{13CC6962-1531-4DD0-BC0C-47DEA185DF81}:

    Media State . . . . . . . . . . . : Media disconnected

    Connection-specific DNS Suffix . :

    Description . . . . . . . . . . . : Microsoft ISATAP Adapter #3

    Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0

    DHCP Enabled. . . . . . . . . . . : No

    Autoconfiguration Enabled . . . . : Yes

    I took the:

    IPv4 Address. . . . . . . . . . . : 192.168.1.4(Preferred)

    Or should I take the physical @ as the @ of my computer?

    I really i don't understand the problem.

    this is the print screen of my error:

    Thanks

  • You really shouldn't be trying to connect your smart device directly to your SQL server unless the smart device is always on you local lan. You might want to look at using RDA (Remote Data Access).

    http://msdn.microsoft.com/en-us/library/ms172917.aspx

    Thanks,

    Neal

  • Hi,

    Finally I depass the problem of the connexion to server by the DB File's attachment. No exception apperas.Still now the problem of the filling of my combobox .I try with sqldataset instead of the sqlreader like this:

    string sConnection = "Data Source=127.0.0.1,1433;Persist Security Info=True;Initial Catalog=GMAO;User ID=sa;Password=sa";

    string sSQL = "SELECT com FROM energie; ";

    SqlConnection conn = new SqlConnection(sConnection);

    SqlCommand comm = new SqlCommand(sSQL, conn);

    DataSet ds = new DataSet();

    SqlCeDataAdapter da = new SqlCeDataAdapter();

    SqlDataReader dr = null;

    try

    {

    comm.Connection.Open();

    da.Fill(ds, "SQL Temp Table");

    foreach(DataRow d in ds.Tables[0].Rows)

    comboBox1.Items.Add(d.ToString());

    }

    catch (SqlException ex)

    {

    //MessageBox.Show("connexion impossible");

    MessageBox.Show(ex.Message);

    return;

    }

    dr.Close();

    comm.Connection.Close();

    }

    but nothing is added to my combobox.

    Thanks in all cases for u collaboration

  • Have you tried binding your dataset to you combobox

    With ComboBox

    .DataSource = ds.tables("SQL Temp Table")

    .DisplayMember = "Column Name"

    END WIth

    or

    ComboBox.DataSource = ds.tables("SQL Temp Table")

    ComboBox.DisplayMember = "Column Name"

    Thanks,

    Neal

  • Hi,

    I really don't understand where I place these 2 instructions.If u wanna help me more,try to give the new code with u changement

    Thanks:-)

  • I am a VB.Net guy, so the syntax may not be perfect but will get you in the right direction.

    string sConnection = "Data Source=127.0.0.1,1433;Persist Security Info=True;Initial Catalog=GMAO;User ID=sa;Password=sa";

    string sSQL = "SELECT com FROM energie; ";

    SqlConnection conn = new SqlConnection(sConnection);

    SqlCommand comm = new SqlCommand(sSQL, conn);

    DataSet ds = new DataSet();

    SqlCeDataAdapter da = new SqlCeDataAdapter();

    SqlDataReader dr = null;

    try

    {

    comm.Connection.Open();

    da.Fill(ds, "SQL Temp Table");

    combobox.datasource = ds.tables(0);

    combobox.displaymember = “com”,

    }

    catch (SqlException ex)

    {

    //MessageBox.Show("connexion impossible");

    MessageBox.Show(ex.Message);

    return;

    }

    dr.Close();

    comm.Connection.Close();

    }

  • Hi,

    I experiment u suggestion but still my combobox wants to be always empty.It refuses to be filled

    what a strong combobox!!!

    Thank u

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply