2011-09-12 32 views
1

我是Crystal Report的新手,我遇到了一个我无法弄清楚的问题。 因为我无法在任何地方找到答案,所以我尝试使用这种方法。防止在Visual Studio 2010的Crystal Report中登录ODBC文本驱动程序

我正在使用Crystal Report,它使用ODBC数据库和文本驱动程序作为数据源。 此报告在使用独立Crystal Report XI打开时非常完美。

当通过VS2010通过基本的c#程序打开它时,总是会提示输入此DB的用户名和密码,尽管没有这个。 因此,我无法访问数据。

奇怪的是,可以通过编辑器中的“浏览字段数据”来访问字段的数据。

有什么我失踪?

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; 
      } 
     } 
    } 
} 

任何帮助将是非常赞赏。

更新:

感谢您的快速响应。不幸的是,他们没有帮助。我仍然得到错误。我试图以下:

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 = logOnInfo.ConnectionInfo; 

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

表的connectionInfos设置,但我仍然得到登录对话框。

回答

1

看一看以下问题的答案: How do I change a Crystal Report's ODBC database connection at runtime?

我们通常通过使用 CrystalDecisions.Shared.ConnectionInfo对象提到那里的“第2部分”提供连接凭据。 通常你没有用户/密码文本文件,所以也许提供空/空作品。

貌似还有另外一个问题,其中家伙有同样的问题,解决它,如下所示: visusal studio embedded crystal report keeps prompting database login?

+0

你的最后一个环节帮助。 Crystal Report似乎需要一个名为SetBaseLogon的用户名和PassWord的虚拟值。所以像“repDoc.SetDatabaseLogon(”UserName“,”UserPW“);”在加载报告之后做的伎俩。感谢您的帮助! – thomacco

+0

非常好知道。不用谢。 –

相关问题