双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

C#连接sql server显示用户sa登录失败

hugo1234567890 hugo1234567890 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用c#写的程序,通过vs连接sql时显示无法打开所在数据库,用户sa登录失败
网上说的修改sql设置的方法都试过了,还是不行
怀疑是我的连接字符串不对,在线等高手解救,急!!
这是我的代码:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace MrCy.BaseClass
{
class DBConn
{
public static SqlConnection CyCon()
{
return new SqlConnection("server=;initial catalog=db_MrCy_Data;user id=sa;password=12345678");

}
}
}

上面是封装的类,下面是调用

SqlConnection conn = BaseClass.DBConn.CyCon();
conn.Open();
SqlCommand cmd = new SqlCommand("select count(*) from tb_User where UserName='" + txtName.Text + "' and UserPwd='" + txtPwd.Text + "'", conn);
int i = Convert.ToInt32(cmd.ExecuteScalar());
if (i > 0)
...全文
评论 13
收藏 已收藏
分享
返回顶部
hugo1234567890
C# 111,129 成员 642,540 内容