使用sql 2008服务器的连接字符串错误 [英] connection string error using sql 2008 server

查看:67
本文介绍了使用sql 2008服务器的连接字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Windows应用程序。使用 sql server  2008  。我正在获取连接字符串问题,而连接到 .mdf 文件    此位置c\folder\file.mdf。 
我所做的将解释你会得到明确的结论。
首先 所有我做了什么我在 1 数据库 > sql 表。现在我解除了它。 来自 c:\program files\sql server\data\mydb.mdf& mydblog.ldf,我复制了桌面。现在来自我的应用程序 我输入 text 然后点击创建按钮event it ic创建一个texbox1。 text .mdf textbox1log.ldf。现在我希望 连接到这个创建的数据库 文件

我已经喜欢这个连接字符串,但 给我连接< span class =code-keyword>
中止所以 。 SqlConnection con = new SqlConnection(@ Data Source = .\SQLExpress; Integrated security = true; AttachDbFilename = c:\\ \\ maq \ + textbox1。文字 + MDF; Trusted_Connection =是);

帮助我 这个我做了使用 .mdb它 成功但sql给我带来了麻烦。我是新的 使用 sql 如果我做了任何错误,请让我知道我想学到很多。

解决方案

试试这个:

 SqlConnection con =  new  SqlConnection(  数据源=。\\SQLExpress; Integrated security = true; AttachDbFilename = \c:\\maq \\ + textbox1.Text +   \.mdf; Trusted_Connection = Yes); 


I am creating a windows application.using sql server 2008. I am getting connection string problem while connecting to .mdf file which is in this location c\folder\file.mdf. 
what I did will explain you will get clear pucture.
first of all what I did is I have created 1 database in the sql with the tables. now I de-attached it. from c:\program files\sql server\data\mydb.mdf&mydblog.ldf, I copied in desktop. now from my application when ever I am entering a text and then click create button event it ic creating a texbox1.text.mdf and textbox1log.ldf. now I want to connect to this created database file.

I have give like this connection string but it is giving me connection is aborted and so on. SqlConnection con = new SqlConnection(@"Data Source=.\SQLExpress;Integrated security=true;AttachDbFilename=c:\maq\" + textbox1.Text + ".mdf;Trusted_Connection=Yes");

Help me for this I did this using .mdb it is successful but sql giving me trouble. I am new to use sql if I did any mistake please let me know I want learn a lot.

解决方案

Try this :

SqlConnection con = new SqlConnection("Data Source=.\\SQLExpress;Integrated security=true;AttachDbFilename=\"c:\\maq\\" + textbox1.Text + "\".mdf;Trusted_Connection=Yes");


这篇关于使用sql 2008服务器的连接字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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