Hello everybody!
I have such problem: I'm going to make a little application, which will interact with MSSQL databse, located on remote server. Server is my and I can administrate it remotely. There is MSSQL 2005 there. I created a database there, but can not connect using code from my application. May be I have to change some access rights on server? Here is my code:

using System;
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 my_prg
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = "Network Library=DBMSSOCN;Data Source=192.168.0.10,2301;database=mydatabase;User id=myuser;Password=pass;";
            conn.Open();
            DataSet ds = new DataSet();
            SqlDataAdapter daDealers = new SqlDataAdapter("SELECT * FROM dealer",conn);
            daDealers.Fill(ds);
            DataTable tbl = ds.Tables["Table"];
            foreach (DataRow row in tbl.Rows)
            {
                foreach (Object val in row.ItemArray)
                {
                    MessageBox.Show(val.ToString());
                }
            }
        }
    }
}

There is a Windows Server 2003 installed on server, myuser - is a windows administrator. When I trying to connect I receive an error that programm can not connect, connection was refused by remote computer. Thank you very much for help.

Check from SQL Server Surface Area Configuration on the Server and check if it allows remote connections or not. Please mention exactly the exception you get.
Or
Change the connection string to "Data Source=192.168.0.10;database=mydatabase;User id=myuser;Password=pass"
Or check with the administration group 2301 is the SQL Server port or 1433?

Dear,

Check the type of authentication : SQL or Windows under which your database is created.

Hello!

Thank you, but I already tryed all thing you wrote.... Nothing .... But, whait ..hmmm, I'll write later. Thanx.

Message error is in russian, but here is a approx. translate:

"Server connection error. When connecting SQL Server 2005, probably reason of this error is that standart parameters of SQL Server not allow remote connections (provider: TCP provider, error: 0 - connection not established, because remote computer refused connection query)"

Urrah! Problem solved. Thanks to everybody who tryed to help. Problem was banal: I used WINDOWS LOGIN and PASSWORD instead SQL user instance. Thanx a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.