Windows窗体连接到本地数据库

时间:2017-09-20 21:22:13

标签: c# .net winforms

我使用visual studio 2015创建了一个非常基本的Windows窗体应用程序。 添加了一个基于服务的数据库(mdf数据库),并创建了一个表。 数据库已添加到服务探索中,我可以在设置文件中看到连接字符串。

我很简单,试图打开与数据库的连接,以便能够写入它。似乎找不到任何基本的例子.. 试图用这个: -

  using (var con = new 
SqlConnection(Properties.Settings.Default.MyConnectionString))
                {
                    con.Open();

                }

            }

但没有运气。似乎得到以下错误

A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

我的连接字符串: -

Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirector‌​y|\Data\mydb.mdf;Int‌​egrated Security=True 

0 个答案:

没有答案
相关问题