none
Connectionstring RRS feed

  • Question

  • While creating  dataset in Memory I was working on similar code  mentioned in form is as follow: 

    protected void Page_Load(object sender, EventArgs e)

        {

            conn = new OdbcConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);

            conn.Open();

     

            if (!Page.IsPostBack)

            {

                runRptViewer();

            }

        }

     

        private void rptGetDataset()

        {

            DataSet ds = new DataSet();

            ds.DataSetName = "dsNewDataSet";

            string sql = "";

            sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";

            OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);

            ds.GetXmlSchema();

            da.Fill(ds);

            ds.WriteXmlSchema(_path + "/App_Code/Ds.xsd");

            ds.WriteXml(_path + "/App_Code/Ds.xml");

        }

     

        private DataTable getData()

        {

            DataSet dss = new DataSet();

            string sql = "";

            sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";

            OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);

            da.Fill(dss);

            DataTable dt = dss.Tables[0];

            return dt;

        }

     

        private void runRptViewer()

        {

            this.ReportViewer1.Reset();

            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");

            ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());

            this.ReportViewer1.LocalReport.DataSources.Clear();

            this.ReportViewer1.LocalReport.DataSources.Add(rds);

            this.ReportViewer1.DataBind();

            this.ReportViewer1.LocalReport.Refresh();

        }

    In this project I am using SQL server 2014, VS 2014, ReportViewer version 11.3 and my code is failing at  Multiple  places like 

    conn = new


    Vijay Patel

    • Moved by Bob Beauchemin Wednesday, August 19, 2015 4:42 PM Moved to the forum for client-side SqlClient for best results
    Wednesday, August 19, 2015 3:32 PM

Answers

All replies

  • Could you provide how your connection string looks and copy/paste the call stack here?
    Tuesday, August 25, 2015 11:10 AM
  • Hi Vijay Patel,

    --> my code is failing at  Multiple  places like    conn = new

    You could share the error message with us, In my opinion, The error in this line means it can't create a connection with the connectionstring. Maybe there is something wrong with your connectionstring.

    You could refer to this to check your connectstring: https://msdn.microsoft.com/en-us/library/system.data.odbc.odbcconnection.connectionstring(v=vs.110).aspx

    "Driver={SQL Server};Server=(local);Trusted_Connection=Yes;Database=AdventureWorks;"
    
    "Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;Persist Security Info=False;Trusted_Connection=Yes"
    
    "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\bin\Northwind.mdb"
    
    "Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\bin\book1.xls"
    
    "Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\bin"
    
    "DSN=dsnname"

    If you have any other concern regarding this issue, please feel free to let me know.

    Best regards,
    Youjun Tang



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, August 26, 2015 3:12 AM
  • First, since you're using SQL Server, you'd be better off not using ODBC ... you should use OleDb instead. The System.Data.SqlClient namespace has classes sub-classed from OleDb classes specifically for use with SQL Server. Use the SqlConnection and SqlDataAdapter classes.

    Also, try taking a look at my blog post for an easy way to determine the correct connection string:
    http://geek-goddess-bonnie.blogspot.com/2015/02/easy-peasy-connection-strings.html

    Hope that helps ...


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com


    Saturday, August 29, 2015 4:55 PM