连接本地数据库mdf Visual Studio [英] Connect local database mdf Visual Studio

查看:634
本文介绍了连接本地数据库mdf Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从visual studio 2013创建了一个mdf数据库,并在表中存储了一些信息。

I have created a mdf database from visual studio 2013 and stored some informations in the table.

我的问题是我不能连接到我的本地数据库,信息从表。
这是我的connect代码:

My problem is I can`t connect to my local database and select informations from table. This is my code for connect:

string con = "Data Source=intrebari.mdf;Integrated Security=True;";

string queryString = "Select * FROM dbo.intrebari"; //update as you feel fit of course for insert/update etc

using (SqlConnection connection = new SqlConnection(con))
{
    connection.Open();
    SqlDataAdapter adapter = new SqlDataAdapter();
    SqlCommand command = new SqlCommand(queryString, connection);

    command.ExecuteNonQuery();

    data = new DataSet();
    adapter.Fill(data);
    MessageBox.Show(data.ToString());

    connection.Close();
}

错误:


建立与SQL Server的连接时发生网络相关或实例特定的错误。

A network-related or instance-specific error occurred while establishing a connection to SQL Server.

我已经解除阻止1433端口与防火墙,但没有成功。这是我的视觉工作室作品的印刷品。

I already unblocked 1433 port with firewall but no succes. Here is a print to my visual studio work.

http:// imgur.com/CwfrWwo

推荐答案

您不能直接使用数据库文件。您必须通过DB服务器访问它。更新查询字符串,您可以此处找到正确的连接字符串。如果没有安装Management Studio,则可以使用MS STUDIO中默认安装的SQLExpress实例,连接字符串为此处

You can't directly use database file. You have to access it through DB server. Update your query string, you can find the proper connection strings Here. If you don't have Management studio installed, you can use the SQLExpress instance installed by default in MS STUDIO, the connection string is HERE .

这篇关于连接本地数据库mdf Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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