I am continuing with my SMO learning and again I am blocked.
Something is missing in this method that I am not able to see.
The view I have previously created it without problems, but when I try creating the delete method sends me the following message:
Reference or object Not instantiated to an object.
I hope a charitable soul lends me a hand.
- private void BtnBorrarVista_Click(object sender, EventArgs e)
- {
- try
- {
- if (MessageBox.Show("Está intentando borrar la Vista " + textBoxBorrarVista.Text + " ¿Está seguro de que quiere eliminarla?", "¡Atención!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
- {
- m_Server = new Server(cmbServerName.Text);
- Database myNewDatabase = m_Server.Databases[cmbDbName.Text];
- Microsoft.SqlServer.Management.Smo.View view = myNewDatabase.Views[textBoxBorrarVista.Text];
- view.Drop();
- MessageBox.Show("La Vista " + textBoxBorrarVista.Text + " se borró con éxito");
- }
- else
- {
- MessageBox.Show("Operación abortada. La Vista " + textBoxBorrarVista.Text + " no se ha borrado");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message.ToString());
- }
- }