I have been developing since the beginning of December 2016 a project to register tool loan vouchers for my school and I have used an sql database to keep the record. I added a local sql database following the following youtube tutorial:
"Insert Queries Modify Delete and Search in VB 2010 and 2008" (the video lasts 17 minutes with 45 seconds I can not add the link because I have low level in the forum, besides that in the video the author programs in C ++ and I program in C #)
And after having handled the queries (the Queries) of the database (which work correctly) I wanted to add a form to support the database following the following tutorial:
When I tried to do a backup, I did not do anything, and then I put the try and catch statements as a comment to see the error when trying again, the following error appeared:
SqlException was unhandled
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. (provider: SQL Network Interfaces, error: 26 - Error Locating Server / Instance Specified)
and I leave the screenshot of the error: then I put the complete code of the form:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace Base_de_datos_ITQ
{
public partial class Respaldo_duv : Form
{
SqlConnection con = new SqlConnection(Base_de_datos_ITQ.Properties.Settings.Default.Base_de_datosConnectionString);
public Respaldo_duv()
{
InitializeComponent();
}
private void button_duv_examinar_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialogo = new FolderBrowserDialog();
if (dialogo.ShowDialog() == DialogResult.OK)
{
textBox_duv_dirección_respaldo.Text = dialogo.SelectedPath;
}
}
private void button_duv_respaldar_Click(object sender, EventArgs e)
{
string database = con.Database.ToString();
//try
{
if (textBox_duv_dirección_respaldo.Text == string.Empty)
{
MessageBox.Show("please enter backup file location");
}
else
{
string cmd = "BACKUP DATABASE [" + database + "] TO DISK='" + textBox_duv_dirección_respaldo.Text + "\" + "database" + "-" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".bak'";
using (SqlCommand command = new SqlCommand(cmd, con))
{
if (con.State != ConnectionState.Open)
{
con.Open();//aquí es donde se marca el error
}
command.ExecuteNonQuery();
con.Close();
MessageBox.Show("database backup done successefully");
}
}
}
//catch
{
}
}
}
}
Note that it is written in C #.
I must add that I am studying electronic engineering and not systems or computing, therefore I am not in my field (normally what I program are microcontrollers with C ++, that is, low level languages) and it is the first time I use databases sql. I give thanks in advance to all who respond.