none
big problem with database connection or security RRS feed

  • Question

  • hi i have a confuse problem that i use a temporary table and use it for sending an arry of parameters to stored proceure the stored procceure used a data source to Crystalreport and i write the follow codes

     MyDB = new DB();\\opening the connection

    string MyQuery = "SP_Create_TempTable";//creating the temptable

    SqlCommand MyComm = new SqlCommand(MyQuery, MyDB.MyConn);

     MyComm.CommandType = CommandType.StoredProcedure;

     MyComm.ExecuteNonQuery();

     foreach (CheckedListBoxItem I in CFB.checkedComboBoxEdit1.Properties.Items)

    { if (I.CheckState == CheckState.Checked) { string MyQuery2 = "SP_Insert_TempTable";//inserting values

     SqlCommand MyComm2 = new SqlCommand(MyQuery2, MyDB.MyConn); MyComm2.CommandType = CommandType.StoredProcedure

    ; SqlParameter Param1 = new SqlParameter("@CityID", I.Value);

     MyComm2.Parameters.Add(Param1);

    MyComm2.ExecuteNonQuery(); } }

    //here the codes for the crystalreport

    ConditionForBuy1 CR = new ConditionForBuy1(); CR.DataSourceConnections[0].SetConnection (DB.ServerName,"SyriaDatabase", DB.ServerUser, DB.ServerPassword); crystalReportViewer1.ReportSource = CR;

     MyDB.CloseConn();

    when i run the application on the clients computer the crystalreportviewer show me a form for login to database like this

    Sever Name:DB-SRV

    DataBaseName:               //empty and the box is diabled

    login Name:MyName

    Password:           //empty

    i ask some friends and the told me to make my database user is an owner to avoid the problem i made him a sysadmin,but the problem still apper i dont know what to do or where is the problem is it coz the temp table??or coz there is a wrong in the code???or its a database problem??? Plz Help me

    Tuesday, November 15, 2011 7:44 PM

Answers

  • Hi Aboudeh,

    Please try to add the code below.

        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigueCrystalReport();
        }

    private void ConfigueCrystalReport()
        {
            ReportDocument myReport
    = new ReportDocument();
            TableLogOnInfo myLogInfo
    = new TableLogOnInfo();
           
    string strPath = Server.MapPath("MyCrystalReport.rpt");

            myReport.Load(strPath);
           
    this.CrystalReportViewer1.ReportSource = myReport;       

            myLogInfo.ConnectionInfo.ServerName
    = "your server name";
            myLogInfo.ConnectionInfo.DatabaseName
    = "your database name";
            myLogInfo.ConnectionInfo.UserID
    = "your login id";
            myLogInfo.ConnectionInfo.Password
    = "your password";
            myReport.Database.Tables[
    0].ApplyLogOnInfo(myLogInfo);
           
            myReport
    = null;
            myLogInfo
    = null;    
        }

       

    Best Regards
    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 3:25 AM
    Moderator

All replies

  • hi i have a confuse problem that i use a temporary table and use it for sending an arry of parameters to stored proceure the stored procceure used a data source to Crystalreport and i write the follow codes

     MyDB = new DB();\\opening the connection

    string MyQuery = "SP_Create_TempTable";//creating the temptable

    SqlCommand MyComm = new SqlCommand(MyQuery, MyDB.MyConn);

     MyComm.CommandType = CommandType.StoredProcedure;

     MyComm.ExecuteNonQuery();

     foreach (CheckedListBoxItem I in CFB.checkedComboBoxEdit1.Properties.Items)

    { if (I.CheckState == CheckState.Checked) { string MyQuery2 = "SP_Insert_TempTable";//inserting values

     SqlCommand MyComm2 = new SqlCommand(MyQuery2, MyDB.MyConn); MyComm2.CommandType = CommandType.StoredProcedure

    ; SqlParameter Param1 = new SqlParameter("@CityID", I.Value);

     MyComm2.Parameters.Add(Param1);

    MyComm2.ExecuteNonQuery(); } }

    //here the codes for the crystalreport

    ConditionForBuy1 CR = new ConditionForBuy1(); CR.DataSourceConnections[0].SetConnection (DB.ServerName,"SyriaDatabase", DB.ServerUser, DB.ServerPassword); crystalReportViewer1.ReportSource = CR;

     MyDB.CloseConn();

    when i run the application on the clients computer the crystalreportviewer show me a form for login to database like this

    Sever Name:DB-SRV

    DataBaseName:               //empty and the box is diabled

    login Name:MyName

    Password:           //empty

    i ask some friends and the told me to make my database user is an owner to avoid the problem i made him a sysadmin,but the problem still apper i dont know what to do or where is the problem is it coz the temp table??or coz there is a wrong in the code???or its a database problem??? Plz Help me




    • Edited by Aboudeh Tuesday, November 15, 2011 7:04 PM
    • Merged by Dummy yoyoModerator Thursday, November 17, 2011 9:12 AM Merge them to keep in the same topic.
    Tuesday, November 15, 2011 6:50 PM
  • Hi Aboudeh,

    Please try to add the code below.

        protected void Page_Load(object sender, EventArgs e)
        {
            ConfigueCrystalReport();
        }

    private void ConfigueCrystalReport()
        {
            ReportDocument myReport
    = new ReportDocument();
            TableLogOnInfo myLogInfo
    = new TableLogOnInfo();
           
    string strPath = Server.MapPath("MyCrystalReport.rpt");

            myReport.Load(strPath);
           
    this.CrystalReportViewer1.ReportSource = myReport;       

            myLogInfo.ConnectionInfo.ServerName
    = "your server name";
            myLogInfo.ConnectionInfo.DatabaseName
    = "your database name";
            myLogInfo.ConnectionInfo.UserID
    = "your login id";
            myLogInfo.ConnectionInfo.Password
    = "your password";
            myReport.Database.Tables[
    0].ApplyLogOnInfo(myLogInfo);
           
            myReport
    = null;
            myLogInfo
    = null;    
        }

       

    Best Regards
    Allen Li [MSFT]
    MSDN Community Support | Feedback to us
    Thursday, November 17, 2011 3:25 AM
    Moderator
  • Aboudeh,

    Why did you tell us what the program does? This does not appear to be a C# language question (which this forum is), but database access issue from a program that happens to be C#.

    Because it is a connection issue, is the database local to the user (ie on the user's machine) or remote?

     

    HTH


    William Wegerson (www.OmegaCoder.Com)
    Thursday, November 17, 2011 8:32 AM