У меня возникли проблемы при получении мой логин на работу и хотел бы некоторый опыт, ниже кодирование от Visual Studio:Ошибка при создании входа с использованием C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace CO6009DissertationV5
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("Data Source=SQL2016.FSE.Network;Initial Catalog=db_1430715_co6009_dissertation;Persist Security Info=True;User ID=user_db_1430715_co6009_dissertation");
**cn.Open();**
SqlCommand cmd = new SqlCommand("select * from tbl_users where username = '" + txtUsername.Text + "', and password = '" + txtPassword.Text + "' ", cn);
SqlDataReader dr;
dr = cmd.ExecuteReader();
int count = 0;
while (dr.Read())
{
count += 1;
}
if (count == 1)
{
MessageBox.Show("OK");
frmWelcome1 formDefault = new frmWelcome1();
formDefault.Show();
}
else if (count > 0)
{
MessageBox.Show("Duplicate username amd password");
}
else
{
MessageBox.Show("Username or password is not correct");
}
txtUsername.Clear();
txtPassword.Clear();
///this.Hide();
//frmWelcome1 formDefault = new frmWelcome1();
//formDefault.Show();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
базы данных из SQL Management Studio:
CREATE table tbl_users
(
userid int PRIMARY KEY IDENTITY,
username varchar(50) NULL,
password varchar(50) NULL,
role varchar (50) NULL,
)
Более подробно
{"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)"}
Когда я пытаюсь запустить код и введите имя пользователя и пароль, он дает мне ошибка в cn.Open(), говоря, что sqlException не был обработан.
Пожалуйста, помогите.
, пожалуйста, взгляните на [how-to-ask] (http://stackoverflow.com/help/how-to-ask) – swe
У вас есть информация о пароле в строке подключения? –
Это ошибка, которую я получил: – AdrianAndrews