本文介绍了使用sql 2008服务器的连接字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个Windows应用程序。使用 sql server 2008 。我正在获取连接字符串问题,而将连接到 .mdf 文件 此位置c\folder\file.mdf。 我所做的将解释你会得到明确的结论。 首先 所有我做了什么是我在 sql 表。现在我解除了它。 来自 c:\program files\sql server\data\mydb.mdf& mydblog.ldf,我复制了在桌面。现在来自我的应用程序 我输入 text 和 然后点击创建按钮event it ic创建一个texbox1。 text .mdf 和 textbox1log.ldf。现在我希望 将连接到这个创建的数据库 文件。 我已经喜欢这个连接字符串,但 给我连接 中止和所以 。 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服务器的连接字符串错误
发布评论