C#连接SQL数据库 未处理System.Data.SqlClient.SqlException Message=用户 'sa' 登录失败。

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSy... using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace KTVData
{
class DBexec
{
public static bool exec(string command)
{
bool tag = false;
SqlConnection conn = new SqlConnection(ConfigClass.configValue);
SqlCommand cmd = new SqlCommand(command, conn);
try
{
conn.Open();
if (cmd.ExecuteNonQuery() > 0)
{
tag = true;
}
}
catch
{
tag = false;
}
finally
{
cmd.Dispose();
conn.Dispose();
conn.Close();
}
return tag;
}
public static DataSet Select(string command)
{
SqlDataAdapter adpt = new SqlDataAdapter(command, ConfigClass.configValue);
DataSet ds = new DataSet();
adpt.Fill(ds);
return ds;
}
public static int exec(string command, int i)
{
int tag = 0;

SqlConnection conn = new SqlConnection(ConfigClass.configValue);
SqlCommand cmd = new SqlCommand(command, conn);

try
{
conn.Open();
tag = cmd.ExecuteNonQuery();
}
catch
{
tag = -1;
}
finally
{
cmd.Dispose();
conn.Dispose();
conn.Close();
}
return tag;
}
}
}
adpt.Fill(ds);
错误指向这里
展开
 我来答
匿名用户
推荐于2017-10-20
展开全部
用户 'sa' 登录失败与你上面的代码没有任何关系,你要解决这问题要从两方面入手:1、你的数据库连接字符串是否正确 2、你的数据库是否设置为可以连接状态
samlldu
2017-10-23 · TA获得超过225个赞
知道小有建树答主
回答量:251
采纳率:62%
帮助的人:30万
展开全部
你数据库配置的sa的密码错了,这个提示的很清楚
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
transger
2016-05-10 · TA获得超过2万个赞
知道大有可为答主
回答量:1.4万
采纳率:69%
帮助的人:4964万
展开全部
报登陆失败一般就是数据库密码不对哦,手工登陆能行不?
追问
在哪儿查看数据库密码呢?手工登录是指使用user ID吗?怎么弄?
追答
数据库的登陆用户名和密码,在你的代码里面应该有啊
手工登陆嘛,sa应该是sqlserver数据库吧,用管理控制台登陆
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式