Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq to sql LINQ入门问题_Linq To Sql - Fatal编程技术网

Linq to sql LINQ入门问题

Linq to sql LINQ入门问题,linq-to-sql,Linq To Sql,我正在尝试在LINQ建立我的hello world程序 执行以下代码时: (这是我的LINQ to SQL类,由VS2008生成。) 我从SQL Server收到以下错误消息 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that

我正在尝试在LINQ建立我的hello world程序

执行以下代码时:

(这是我的LINQ to SQL类,由VS2008生成。)

我从SQL Server收到以下错误消息

A network-related or instance-specific error occurred while 
establishing a connection to SQL Server. The server was not found 
or was not accessible. Verify that the instance name is correct 
and that SQL Server is configured to allow remote connections. 
(provider: Named Pipes Provider, error: 40 - Could not open a 
connection to SQL Server)

如何解决这个问题?

您正在将字符串literal
“LINQ\u TestConnectionString”
传递到构造函数中,因此它将其视为连接字符串本身。这不是连接字符串,只是连接字符串设置的名称

无参数构造函数-将自动使用LINQ_TestConnectionString设置:

PersonDataContext dc = new PersonDataContext();

或者,传入一个真正的连接字符串。

您正在将字符串literal
“LINQ\u TestConnectionString”
传入构造函数-因此它将其视为连接字符串本身。这不是连接字符串,只是连接字符串设置的名称

无参数构造函数-将自动使用LINQ_TestConnectionString设置:

PersonDataContext dc = new PersonDataContext();

或者,传入一个真实的连接字符串。

由于您从数据库拖放了表,连接字符串已经存在,只需使用默认的constractor:

new PersonDataContext();
如果要传递连接字符串,请使用以下命令:

Data Source=ComputerName\Instancename;Initial Catalog=DataBaseName;Persist Security Info=True;

由于您从数据库中拖放了表,连接字符串已经存在,请使用默认构造函数:

new PersonDataContext();
如果要传递连接字符串,请使用以下命令:

Data Source=ComputerName\Instancename;Initial Catalog=DataBaseName;Persist Security Info=True;