We help IT Professionals succeed at work.

SQL Connection

Rama Tito
Rama Tito used Ask the Experts™
on
Hi, Server Name is : TRamanah\SQLEXPRESS
Even after i tried input  Data Source as TRamanah or TRamanah\SQLEXPRESS or (local)\SQLEXPRESS. Doesn't seems working. I just want to check my connection status?
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection cs =  new SqlConnection("Data Source =TRamanah; Initial Catalog=CAMS; User ID = sa;Password = abc123");
            cs.Open();
            MessageBox.Show (cs.State.ToString());
            cs.Close();
        }
    }
}

Open in new window

SQL-connection.JPG
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
SQLEXPRESS connectin string used like tjis

Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True

OR

using System.Data.SqlClient;

SqlConnection conn = new SqlConnection();
conn.ConnectionString =
     "Data Source=.\SQLExpress;" +
     "User Instance=true;" +
     "User Id=UserName;" +
     "Password=Secret;" +
     "AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();


Refer this links for more details
http://www.dofactory.com/Connect/Connect.aspx#sqlexpress
http://msdn.microsoft.com/en-us/library/ms247257.aspx
Rama TitoProgrammer

Author

Commented:
HI Thank you, for the information.

Its works after i did insert Data Source as  : TRamanah\\SQLEXPRESS.

As attached in coding column.
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection cs =  new SqlConnection("Data Source =TRamanah\\SQLEXPRESS; Initial Catalog=CAMS; User ID = sa;Password = abc123");
            cs.Open();
            MessageBox.Show (cs.State.ToString());
            cs.Close();
        }
    }
}

Open in new window