Binier
Binier

Reputation: 1107

How to connect to SQL Server from a C# program on another computer

SqlConnection con = new SqlConnection("server=192.168.0.100,1400;user=Users;password=password;database=Example1;integrated security = true;");

SqlDataAdapter sda = new SqlDataAdapter();
DataTable dbdataset = new DataTable();

BindingSource bsource = new BindingSource();
SqlCommand cmd = new SqlCommand();

public void loaddata()
{
    try
    {
        SqlCommand cmdatabbase = new SqlCommand(" select * from Example1.dbo.Users ;", con);

        sda.SelectCommand = cmdatabbase;

        sda.Fill(dbdataset);

        bsource.DataSource = dbdataset;
        dataGridView1.DataSource = bsource;
    }
    catch (Exception ex)
    {
       MessageBox.Show(ex.ToString());
    }

This is my code in C# Winforms application. On my computer it is working but from another computer it shows error (it can't load table in datagridview). I added rule in firewall and I enable tcp in SQL Server Configuration Manager but it still doesn't work! I tried every solution that found in internet but it didn't work.

a busy cat http://non-98.ucoz.com/Untitled5.jpg

I saw this in another computer when running a program.

Upvotes: 0

Views: 1264

Answers (2)

user2968347
user2968347

Reputation: 21

I think this is due to accessibility of the sever.Try either integrated security =False or update connection string

Upvotes: 0

ms_devel
ms_devel

Reputation: 492

You must change the integrated security from true to false. Check this connection strings

Upvotes: 1

Related Questions