如何检查数据库是否正确附加到项目? [英] How to check either a database is properly attach to a project or not ?

查看:84
本文介绍了如何检查数据库是否正确附加到项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个学校项目。这个项目是用C#窗体,实体框架和SQL Server 2008构建的。我想知道是否有人想检查项目运行的开始,数据库文件是否正确附加到项目,我们如何做到这一点使用C#或实体框架。

I'm working on a school project. This project is being built in C# windows forms , Entity framework and SQL Server 2008.I want to know if someone want to check on the start of project running that either the database file is properly attached to project or not, how we can do it using C# or entity framework.

推荐答案

有多种方法可以检测哪些服务器/ SQL服务可用,但我建议您尝试执行一些查询/ catch并检查任何异常。您很快就会发现无法连接到SQL服务器的那个。然后你知道它不可用。



听起来怎么样?
There are ways to detect what servers / SQL services are available, but I'd suggest you try to perform some query with a try/catch and check any exceptions. You'll soon find the one that says "unable to connect to SQL server". Then you know it's unavailable.

How does that sound?


这篇关于如何检查数据库是否正确附加到项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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