SQL Server R2连接问题 [英] SQL Server R2 Connection problem

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

问题描述

我已经尝试了两天,将我的应用程序连接到数据库.我建立了C#应用程序,可以正常工作.现在,我想使用此应用程序的第二台机器.我安装了sql server r2,将数据库.mdf和日志文件放入数据文件夹.更改了我的应用程序的连接字符串,但无法连接到数据库.数据源=.\ SQLEXPRESS;初始目录= Med; Trusted_Connection =正确,这是字符串.如果我更改与Master连接的数据库名称(Med),则说明成功.我必须安装sql server managmet studio吗?没有它,我无法连接?有人可以帮我吗?

Im trying already two days to connect my application to database. I built c# applictaion which works correctly. Now i want to use this app second machine. I installed sql server r2 put database .mdf and log file into data folder. changed connection string my app but it cannot connect to database. Data Source=.\SQLEXPRESS;Initial Catalog=Med;Trusted_Connection=True this is con string. If i change database name(Med) with Master connection is succesfull. Am i must install sql server managmet studio? Without it i cannot connect? Can anyone help me?

推荐答案

您是说您仅将Med db的数据库文件复制到了数据目录.如果是这样,那还不够.您必须将数据库注册"到SQL Server实例.一种选择是您在原始服务器上进行备份,然后在目标服务器中还原该备份.另一种选择是从源分离数据库,然后将其附加到目标计算机.

更多信息:
- http://msdn.microsoft.com/en-us/library/ms177429.aspx [ ^ ]
- http://msdn.microsoft.com/en-us/library/ms190794.aspx [ ^ ]
Do you mean you have only copied the database files for the Med db to data directory. If that''s the case, it''s not enough. You have to ''register'' the database to the SQL Server instance. One option is that you take a backup on the original server and restore the backup in target server. Another option is to detach the database at source and then attach it at target machine.

More info:
- http://msdn.microsoft.com/en-us/library/ms177429.aspx[^]
- http://msdn.microsoft.com/en-us/library/ms190794.aspx[^]


在VS中尝试一下:
1)打开服务器资源管理器"窗格
2)如果未列出您的数据库,请右键单击数据连接",然后选择添加连接...",请按照以下步骤添加数据库.
3)单击您的数据库名称以突出显示它.
4)查看属性"窗格-它将包含连接字符串.
5)右键单击字符串全选",右键单击复制"
6)将字符串粘贴到程序中(或最好使用应用程序设置字符串,以便于更改),然后尝试尝试.
Try this in VS:
1) Open the Server Explorer pane
2) If your database is not listed, right click on "Data Connections" and select "Add Connection..." Follow the steps to add your DB.
3) Click on your database name to highlight it.
4) Look at the Properties pane - it will contain the connection string.
5) Right click the string, "Select All", Right click "Copy"
6) Paste the string into your program (or preferably use an application setting string so it is easy to change) and try that.


这篇关于SQL Server R2连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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