سؤال

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;
            }
        }
    }
}

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top