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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server). The number of line in which i get error is line 107 (con.Open).
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Data.Sql; using System.Data.SqlClient; using System.Configuration; using System.Net; using System.Collections.Specialized; using System.Data; using System.Text.RegularExpressions; namespace Sup { /// <summary> /// Interaction logic for Signup.xaml /// </summary> public partial class Signup : Window { public Signup() { InitializeComponent(); } private void Reset() { textBoxAddress.Text = ""; textBoxEmail.Text = ""; textBoxFirstName.Text = ""; textBoxLastName.Text = ""; passwordBox1.Password = ""; passwordBoxConfirm.Password = ""; } private void registerButton_Click(object sender, RoutedEventArgs e) { if (textBoxEmail.Text.Length == 0) { MessageBox.Show("Enter an email."); textBoxEmail.Focus(); } else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")) { MessageBox.Show("Enter a valid email."); textBoxEmail.Select(0, textBoxEmail.Text.Length); textBoxEmail.Focus(); } else { string firstname = textBoxFirstName.Text; string lastname = textBoxLastName.Text; string email = textBoxEmail.Text; string password = passwordBox1.Password; if (passwordBox1.Password.Length == 0) { MessageBox.Show("Enter password."); passwordBox1.Focus(); } else if (passwordBoxConfirm.Password.Length == 0) { MessageBox.Show("Enter Confirm password."); passwordBoxConfirm.Focus(); } else if (passwordBox1.Password != passwordBoxConfirm.Password) { MessageBox.Show("Confirm password must be same as password."); passwordBoxConfirm.Focus(); } else { string address = textBoxAddress.Text; SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=logins;Integrated Security=SSPI"); con.Open(); SqlCommand cmd = new SqlCommand("Insert into Registration (FirstName,LastName,Email,Password,Address) values('" + firstname + "','" + lastname + "','" + email + "','" + password + "','" + address + "')", con); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); con.Close(); MessageBox.Show("You have Registered successfully."); Reset(); } } } } }
From link[^]:Basically, when you failed to connect to your SQL Server, the issue could be: 1) Network issue, 2) SQL Server configuration issue. 3) Firewall issue, 4) Client driver issue, 5) Application configuration issue. 6) Authentication and logon issue.
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=logins;Integrated Security=SSPI");
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)