将包含MDF文件的项目部署到外部计算机 [英] Deploying a project that includes an MDF file to an external computer

查看:100
本文介绍了将包含MDF文件的项目部署到外部计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我有一个Windows Forms应用程序,其中包括一个dataGridView,其数据源是一个名为VoRteXData.mdf的MDF文件.现在,我需要将其部署到外部位置.对于我的表单代码,它包括:

Basically, I have a Windows Forms Application that includes a dataGridView with the DataSource being an MDF file named VoRteXData.mdf. Now, I need to deploy this to an external location. For my forms code, it includes:

    private void Form1_Load(object sender, EventArgs e)
    {
        SqlConnection sqlCon = new SqlConnection();
        sqlCon.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Moderator\Documents\VoRteXData.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
        sqlCon.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from VoRteXBanTable", sqlCon);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        dataGridView1.DataSource = dt;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        string searchFilter = textBox1.Text;

        for (int i = 0; i < dataGridView1.Rows.Count; i++)
        {
            if (dataGridView1.Rows[i].Cells[0].Value.ToString() == searchFilter)
            {
                dataGridView1.Rows[i].Selected = true;
                dataGridView1.Rows[i].Visible = true;
            }
            else
            {
                dataGridView1.CurrentCell = null;
                dataGridView1.Rows[i].Visible = false;
                dataGridView1.Rows[i].Selected = false;
            }
        }
    }
}

接下来,在我的MDF文件中是一个表和5个字段,其中包含约50条记录.将项目发布到外部计算机后,出现错误消息:与SQL Server建立连接时发生与网络相关或特定于实例的错误.找不到服务器或无法访问该服务器.请验证实例名称是否正确.并且该SQL Server已配置为允许远程连接".但是,我没有使用SQL Server Management Studio,因为我需要将其部署在没有主机的外部位置.我不希望用户安装所有SQL先决条件,因为这太荒谬了.那么,有没有办法让C#完全运行此MDF文件?还是mabye将其免费上传到网络上?

Next, in my MDF file is one table and 5 fields with around 50 records. Upon publishing the project to an external computer, I get an error: "A network-related or instance-specific error occurred while establishing a connection to SQL server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL server is configured to allow remote connections". However, I'm not using SQL Server Management Studio because I need to deploy this at an external location without a host. I don't want the user to install all the SQL prerequisites because, that would be ridiculous. So is there any way to get C# to run this MDF file at all? Or mabye upload it to the web for free?

推荐答案

客户端计算机必须安装了SQL Server Express.您可以通过将其作为前提条件包含在setup.exe中.这只会安装数据库引擎.但是,如果您不希望客户端计算机安装SQL Server Express,则需要更改您的应用程序以使用SQL Server Compact.这样,它将不需要在客户端上安装SQL Server实例.

The client machine must have SQL Server Express installed. You can include this in the setup.exe by including it as a prerequisite. This will only install the database engine. But, if you do not want the client machine to have SQL Server Express installed then you need to change your app to use SQL Server Compact. That way it will not need a SQL Server instance installed on the client.

这篇关于将包含MDF文件的项目部署到外部计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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