DataContext.CreateDatabase()不起作用! [英] DataContext.CreateDatabase() doesn't work!

查看:54
本文介绍了DataContext.CreateDatabase()不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,这是我的测试代码:

Hello, this is my test code:

public class MyDVDs : DataContext
{
 public Table<DVD> DVDs;
 public MyDVDs(string connection) : base(connection) { }
}
[Table(Name="DVDTable")]
public class DVD
{
 [Column(IsPrimaryKey=true)]
 public string Title;
 [Column]
 public string Rating;
}


static void Listing()
{
 MyDVDs db = new MyDVDs("c:\\123\\mydvds.mdf");
 db.CreateDatabase();
}


运行时出现稳定错误:
System.Data.SqlClient.SqlException未处理
消息="网络"建立与SQL Server的连接时发生相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:SQL网络接口,错误:26 - 错误定位指定的服务器/实例)"

所以我有几个问题。首先是自我证据 - 代码有什么问题?第二个可能更有趣 - LINQ将要连接到哪里?我只是不提供任何连接字符串!那么SQL Server LINQ在哪里尝试建立连接?

I get stable error on it run:
System.Data.SqlClient.SqlException was unhandled
  Message="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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"

And so I have a couple of questions. First is self-evidence - what's wrong with code? Second is may be more interesting - WHERE LINQ is going to connect to? I just don't provide any connection string! So where is that SQL Server LINQ try establishing a connection to?

推荐答案

如果您已完成其他部分,它会看起来例如:


MyDVDs

Provided you have completed other parts it would look like:

MyDVDs

db = MyDVDs
@" Server = .\SQLExpress; AttachDbFilename = c:\\ \\123\myDVDs.mdf;数据B ase = myDVDs; Trusted_Connection = yes" );
db.CreateDatabase();

我会先在SQL中进行(开发)并使用designer(或SqlMetal)生成dbml。


这篇关于DataContext.CreateDatabase()不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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