通过.net连接附件.mdf文件 [英] To connect the attachment .mdf file through .net

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

问题描述

我已经安装了SQL Server 2008 R2&使用username = ''sa'' & password = ''pw''
配置服务器混合模式身份验证 我的附件.mdf文件位于d:\ Test文件夹中,并且服务正在运行.

现在,我通过编码连接server2008附件.mdf文件,但未连接.错误消息显示(''建立与服务器的连接时发生错误.当连接到SQL Server 2005时,此失败可能是由于以下事实导致的:在默认设置下SQL Server不允许远程连接.(提供者:SQL网络接口,错误:26-错误指定服务器/实例的位置)'')

我的代码如下:->
--------------------

I have install the SQL server 2008 R2 & configure the server Mixed mode authentication with username = ''sa'' & password = ''pw''
and my attachment .mdf file is located in d:\Test folder and service is running.

Now i connect the server2008 attachment .mdf file through coding but not connect. Error msg shown(''An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'')

My code is below :->
--------------------

SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\MSSQLEXPRESS;AttachDbFilename=D:\Test\db.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();



我该如何解决以上问题??
请帮助我任何指示...



How will i solve above problem???
Please help me any instruction......

推荐答案



利用Web.Config文件的ConnectionStrings部分.

< connectionstrings>
< add name ="conString">
connectionString ="Data Source =<计算机名称> \< sqlexpressinstancename> ;;
database =<您的数据库>
集成安全性= true>
</add>
< connectionstrings>


问候,
Raghu ...
Hi,

Make use of the ConnectionStrings Sction of Web.Config File.

<connectionstrings>
<add name="conString">
connectionString="Data Source=<machinename>\<sqlexpressinstancename>;
database=<your database>
Integrated Security=true">
</add>
<connectionstrings>


Regards,
Raghu...


这篇关于通过.net连接附件.mdf文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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