Click here to Skip to main content
15,887,845 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SQL
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);
               }
        
        }
    }
}
Posted
Updated 13-Aug-14 20:41pm
v3

Check if the Mixed Mode authentication is enabled in SQL Server
 
Share this answer
 
Look at your connection string:
C#
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.
 
Share this answer
 
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 :-)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900