Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# 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 30-Jul-14 3:22am
Edited 13-Aug-14 21:41pm
coded0077.3K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check if the Mixed Mode authentication is enabled in SQL Server
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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 Smile | :)
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web01 | 2.8.150129.1 | Last Updated 14 Aug 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100