开发者

Prevent login of ODBC Text driver in Crystal Report for Visual Studio 2010

开发者 https://www.devze.com 2023-04-04 10:07 出处:网络
I am new to Crystal Report and I have a problem I cannot figure out. Because I cannot find an answer anywhere I try it this way.

I am new to Crystal Report and I have a problem I cannot figure out. Because I cannot find an answer anywhere I try it this way.

I am using a Crystal Report which uses an ODBC database with a text driver as a datasource. This report works perfect when opening it with the standalone Crystal Report XI.

When opening it via VS2010 over a basic c#-program I am always prompted for the Username and Password for this DB, in spite there is none of this. Because of this I cannot access the data.

The strange thing is, that it is possible to access the data of the fields via "Browse Field Data" in the editor.

Is there something I am missing?

namespace CrystalReportsApplication1
{
    public partial class Form1 : Form
    {
        private string reportPath;
        private ReportDocument repDoc = new ReportDocument();
        private FileInfo m_AssemblyCS;
        private DirectoryInfo m_SolutionRoot;

        public Form1()
        {
            InitializeComponent();
            m_AssemblyCS = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
            m_SolutionRoot = m_AssemblyCS.Directory.Parent.Parent.Parent;
            reportPath = string.Empty;
        }

        private void bOpenReport_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = m_SolutionRoot.FullName;
            openFileDialog1.Filter = "rpt files (*.rpt)|*.rpt|All files (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            { 
                reportPath = openFileDialog1.FileName;
                tbReportPath.Text = reportPath;
                repDoc.Load(reportPath);
                crystalReportViewer.ReportSource = repDoc;
            }
        }
    }
}

Update

Unfortunately the se hasn't helped. I still get the error. I tried to following:

private void bOpenReport_Click(object sender, EventArgs e)
{
  OpenFileDialog openFileDialog1 = new OpenFileDialog();
  openFileDialog1.InitialDirectory = m_SolutionRoot.FullName;
  openFileDialog1.Filter = "rpt files (*.rpt)|*.rpt|All files (*.*)|*.*";

  if (openFileDialog1.ShowDialog() == DialogResult.OK)
  { 
    reportPath = openFileDialog1.FileName;
    tbReportPath.Text = reportPath;
    repDoc.Load(reportPath);

    foreach(Table table in repDoc.Database.Tables)
      SetConnectionInfo(table.Name, "dds", "", "", "");

    crystalReportViewer.ReportSource = repDoc;
  }
}

private void SetConnectionInfo(string table, string server, string database, string user, string password)
{ 
  TableLogOnInfo logOnInfo = new TableLogOnInfo();
  logOnInfo = repDoc.Database.Tables[table].LogOnInfo;
  ConnectionInfo connectionInfo = new ConnectionInfo();
  connectionInfo = logOn开发者_开发技巧Info.ConnectionInfo;

  connectionInfo.DatabaseName = database;
  connectionInfo.ServerName = server;
  connectionInfo.Password = password;
  connectionInfo.UserID = user;
  repDoc.Database.Tables[table].ApplyLogOnInfo(logOnInfo);
}

The connectionInfos of the tables are set, but I still get the login-dialog.


Have a look at the answer of the following question: How do I change a Crystal Report's ODBC database connection at runtime?

We normally supply the connection credentials via the "Part2" mentioned there using CrystalDecisions.Shared.ConnectionInfo object. Normally you do not have user/password on text files so maybe providing empty/empty works.

Looks like there is another question where the guy had the same issue and solved it as follows: visusal studio embedded crystal report keeps prompting database login?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号