请解决登录失败用户“sa”的问题.. [英] pls slove problem of login failed user"sa"..

查看:294
本文介绍了请解决登录失败用户“sa”的问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 使用系统; 
使用 System.Collections.Generic;
使用 System.ComponentModel;
使用 System.Data;
使用 System.Drawing;
使用系统。文字;
使用 System.Windows.Forms;
使用 System.Data.SqlClient;
使用 CrystalDecisions.CrystalReports.Engine;

命名空间WindowsApplication4
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender,EventArgs e)
{
try
{
//创建对象 我们的报告
CRYSTALREPORT objrpt = new CRYSTALREPORT();
String ConnStr =( Data Source = 192.168.200.246; Initial Catalog = BackOffice_Report; Persist Security Info = True ;用户ID = sa,密码=);



SqlConnection myconnection = new SqlConnection();

String Query1 = select * from tbl_product;

SqlDataAdapter ad = new SqlDataAdapter(Query1,ConnStr);


DATASET Ds = new DATASET();


//这里my_dt 名称 DataTable我们
//在设计师视图中创建
ad.Fill(Ds, tbl_product);

if (Ds.Tables [ 0 ]。Rows.Count == 0
{
MessageBox.Show( 找不到数据 CrystalReportWith SQL);
return ;
}

//设置数据 source 我们的报告对象
objrpt.SetDataSource(Ds);
objrpt。加载(@ D: \project\WindowsApplication4\WindowsApplication4\CRYSTALREPORT.rpt);
crystalReportViewer1.ReportSource = objrpt;
crystalReportViewer1.Refresh();


//将crystalReportViewer 绑定到我们的报表对象。
crystalReportViewer1.ReportSource = objrpt;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}

}
}
}

解决方案

检查是否在SQL Server中启用混合模式身份验证


查看您的连接字符串:

 字符串 ConnStr =( 数据源= 192.168.200.246;初始目录= BackOffice_Report;持久安全信息= True;用户ID = sa,密码=); 



sa 是特殊的用户通常对数据库具有绝对权限的用户,以及在安装SQL Server时为您构建的id。此安装具有密码,该密码经常更改,并且帐户已完全删除。但是,只有一个非常愚蠢或天真的数据库管理员才能完全清除密码字段,因为这样每个人都可以访问SQL服务器实例中所有数据库的所有表 - 这很危险,绝对不是一个好主意。 />


您需要使用正确的密码,或者(更有可能)使用正确的用户名和密码组合,只能访问您真正需要的数据库/表。


检查MS SQL是否处于混合模式身份验证中



创建一个只能访问BackOffice_Report数据库的新用户登录。 />


给新的登录/数据库用户db_datareader角色,然后它不能改变任何数据,只能选择它们。



这将提供更好的安全性,不要使用sa用户完成这项工作: - )


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;

namespace WindowsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e) 
           {
               try
               {
                   // Creating object of our report
                   CRYSTALREPORT objrpt = new CRYSTALREPORT();
                   String ConnStr = ("Data Source=192.168.200.246;Initial Catalog=BackOffice_Report;Persist Security Info=True;User ID=sa,password=");



                   SqlConnection myconnection = new SqlConnection();

                   String Query1 = "select * from tbl_product";

                   SqlDataAdapter ad = new SqlDataAdapter(Query1, ConnStr);


                   DATASET Ds = new DATASET();


                   // here my_dt is the name of the DataTable which we 
                   // created in the designer view.
                   ad.Fill(Ds, "tbl_product");

                   if (Ds.Tables[0].Rows.Count == 0)
                   {
                      MessageBox.Show("No data Found", "CrystalReportWith SQL");
                       return;
                   }

                   // Setting data source of our report object
                   objrpt.SetDataSource(Ds);
                   objrpt.Load(@"D:\project\WindowsApplication4\WindowsApplication4\CRYSTALREPORT.rpt");
                   crystalReportViewer1.ReportSource = objrpt;
                   crystalReportViewer1.Refresh();


                   // Binding the crystalReportViewer with our report object. 
                   crystalReportViewer1.ReportSource = objrpt;
               }
               catch(Exception ex)
               {
                   MessageBox.Show(ex.Message);
               }
        
        }
    }
}

解决方案

Check if the Mixed Mode authentication is enabled in SQL Server


Look at your connection string:

String ConnStr = ("Data Source=192.168.200.246;Initial Catalog=BackOffice_Report;Persist Security Info=True;User ID=sa,password=");


sa is a "special user" who normally has absolute power over the database, and id constructed for you when you install SQL server. This installation has a password, which is often changed, and the account removed entirely. But it would only be a very stupid or naive database admin who would clear the password field entirely, as this would allow everybody access to all the tables of all the databases in the SQL server instance - dangerous and definitely not a good idea.

You either need to use the correct password, or (more likely) use the proper username and password combination with access only to the databases / tables you really need.


Check if MS SQL is in Mixed Mode authentication

Create a new user login that only has access to "BackOffice_Report" database.

Give the new login/database user "db_datareader" role, then it cannot change any data but only select them.

That will give better security, do not use "sa" user for this job :-)


这篇关于请解决登录失败用户“sa”的问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆