C#2.0连不上sql2005,请达人帮助解答一下.

来源:百度知道 编辑:UC知道 时间:2024/05/05 18:12:59
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ConsoleApplication478
{
class Program
{
static void Main(string[] args)
{
string connectionString = @"Data Source=E:\SQL\telephone directory;Initial Catalog=telephone directory.mdf;Integrated Security=True;Pooling=False";
SqlConnection myConnection = new SqlConnection(connectionString);

myConnection.Open();
SqlCommand myCommand = myConnection.CreateCommand();

myCommand.CommandText="select * from person";
SqlDataReader myDataReader=myCommand.ExecuteReader();

while (myDataReader.Read())
{
Console.WriteLine("\t{0}\t{1}",myDataReader["ID"],myDataReader["nam

Data Source=E:\SQL\telephone directory;Initial Catalog=telephone directory.mdf;Integrated Security=True;Pooling=False";
此句有误吧? dataSource应该是SQlServer的实例名,比如(local)