无法打开数据库连接 [英] Can't open database connection

查看:100
本文介绍了无法打开数据库连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有关于我的SQL Server 2005的问题.我从Microsoft网站安装了"SQL Server Management Studio Express",但由于".open()"行不起作用并且发生了错误,所以我无法运行我的程序.我的代码是在这里:

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 :

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;
        }
    }
}

非常感谢.

推荐答案

您看到的错误是什么?

您启用了TCP/IP连接吗?
http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277

干杯,
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,


这篇关于无法打开数据库连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆