Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a problem about my SQL Server 2005.I installed "SQL Server Management Studio Express from Microsoft site but I can't run my program because ".open()" line doesn't work and error occured.My codes is here :
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DataSetExample
{
    public partial class Form1 : Form
    {
        SqlConnection objConnection = new SqlConnection("server=localhost;database=Pubs;"+
            "IntegratedSecurity=true");
        SqlDataAdapter objDataAdapter = new SqlDataAdapter();
        DataSet objDataSet = new DataSet();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            objDataAdapter.SelectCommand = new SqlCommand();
            objDataAdapter.SelectCommand.Connection = objConnection;
            objDataAdapter.SelectCommand.CommandText =
                "SELECT au_lname, au_fname, title, price " +
                "FROM authors " +
                "JOIN titleauthor ON authors.au_id = " +
                "titleauthor.au_id " +
                "JOIN titles ON titleauthor.title_id = " +
                "titles.title_id " +
                "ORDER BY au_lname, au_fname";
            objDataAdapter.SelectCommand.CommandType = CommandType.Text;
            objConnection.Open();
            objDataAdapter.Fill(objDataSet, "authors");
            objConnection.Close();
            grdAuthorTitles.AutoGenerateColumns = true;
            grdAuthorTitles.DataSource = objDataSet;
            grdAuthorTitles.DataMember = "authors";
            objDataAdapter = null;
            objConnection = null;
        }
    }
}
Thanks a lot.
Posted
Updated 17-May-10 10:56am
v3

1 solution

What is the error you're seeing?

Have you enabled TCP/IP connections?
http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277

Cheers,
 
Share this answer
 
Comments
TheyCallMeMrJames 17-May-10 15:16pm    
Not sure why on the 1-vote...enabling TCP/IP connections is the fix for this 99% of the time...
Pete O'Hanlon 17-May-10 16:57pm    
Awarding 5 because you have given the sensible answer based on the paucity of information. BTW - congratulations on winning the Zune.
TheyCallMeMrJames 17-May-10 17:19pm    
Thanks Pete. And...thanks ;o)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900