自动将数据库附加到sql express [英] attach database to sql express automatically

查看:115
本文介绍了自动将数据库附加到sql express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我已经使用Visual Studio 2010创建了一个winform应用程序并为其创建了一个安装项目.我的应用程序可与sql express一起使用,因此我已将sql express 2008添加到安装程序的先决条件中. 另外,我还使用以下连接字符串连接到我的数据库:

数据源=.\ SQLEXPRESS; AttachDBFileName = | DataDirectory | \ MyDBName.mdf;集成安全性= True;

我的应用程序及其安装项目成功构建,但是当我安装并运行它(甚至通过以管理员身份运行)时,我收到了这样的错误:

无法打开用户默认数据库.登录失败.
此用户登录失败.


Hi all,
I have created a winform application with visual studio 2010 and a setup project for it.my application works with sql express so i have added sql express 2008 to prerequisits of the setup.
In addition i have used the following connection string to connect to my database :

Data Source=.\SQLEXPRESS; AttachDBFileName=|DataDirectory|\MyDBName.mdf; Integrated security=True;

my application and its setup project build successfully but when i have install and run it (even by Run as Administrator) i have receive an error like this :

cannot open a user default database.login failed.
login failed for this user.


what is my mistake??

推荐答案

在连接字符串中传递您的凭据.
并使用集成安全性的持久性安全信息
Pass your credential in connection string.
and use Persist Security Info instaed of Integrated Security
Data Source=.\SQLEXPRESS; AttachDBFileName=|DataDirectory|\MyDBName.mdf;
Persist Security Info=True;User ID=youruserid;Password=password"



检查更多连接字符串
http: //www.connectionstrings.com/sql-server-2008 [ ^ ]



check more connectionstrings
http://www.connectionstrings.com/sql-server-2008[^]


这篇关于自动将数据库附加到sql express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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