我也试图解决这个问题太困难了我尝试使用c#在visualstudio 2010中直接打印我的sap插件中的值,它为我返回了这个错误: ' logonfailed'这是我的代码:
try
{
DataTable matable = new DataTable();
DataSet madataset = new DataSet();
SqlConnection maconnexion = new SqlConnection();
maconnexion.ConnectionString = Menu.connectionString_formatsql;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select oitm.ItemCode ,OITM .ItemName ,OITM .CodeBars,ITM1.Price,@codebars " +
" from OITM,ITM1 where OITM .ItemCode=ITM1 .ItemCode" +
" and OITM.ItemCode =@itemCode" +
" and ITM1 .PriceList = @pricelist ";
cmd.Parameters.Clear();
//cmd.Parameters.Add("@codebars", SqlDbType.VarChar );
//cmd.Parameters["@codebars"].Value = get_codebarre_dessin();
//cmd.Parameters.Add("@itemCode", SqlDbType.VarChar);
//cmd.Parameters["@itemCode"].Value = this.EditText1.Value;
//cmd.Parameters.Add("@pricelist", SqlDbType.SmallInt);
//cmd.Parameters["@pricelist"].Value = Convert.ToInt32(this.ComboBox0.Value);
cmd.Parameters.Add("@codebars", SqlDbType.VarChar);
cmd.Parameters["@codebars"].Value = get_codebarre_dessin();
cmd.Parameters.Add("@itemCode", SqlDbType.VarChar);
cmd.Parameters["@itemCode"].Value = this.EditText1.Value;
cmd.Parameters.Add("@pricelist", SqlDbType.Int);
cmd.Parameters["@pricelist"].Value = Convert.ToInt32(this.ComboBox0.Value);
cmd.Connection = maconnexion;
if (maconnexion.State == ConnectionState.Closed)
{
maconnexion.Open();
}
SqlDataAdapter madataadapter = new SqlDataAdapter(cmd);
// SqlCommandBuilder madatabuilder = new SqlCommandBuilder(madataadapter );
matable.Load(cmd.ExecuteReader());
madataset.Tables.Add(matable);
ReportDocument report = new ReportDocument();
report.Load("BARCODE.rpt");
report.Refresh();
report.DataSourceConnections.Clear();
foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
MessageBox.Show( tableLogOnInfo.ConnectionInfo.ServerName );
MessageBox.Show( tableLogOnInfo.ConnectionInfo.DatabaseName);
MessageBox.Show(tableLogOnInfo.ConnectionInfo.UserID);
MessageBox.Show(tableLogOnInfo.ConnectionInfo.Password.ToString());
MessageBox.Show(tableLogOnInfo.ConnectionInfo.IntegratedSecurity.ToString() );
//table.ApplyLogOnInfo(tableLogOnInfo);
//table.Location = Menu.company.CompanyDB + ".dbo." + table.Name.ToString();
}
foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo.AllowCustomConnection = true;
tableLogOnInfo.ConnectionInfo.ServerName = Menu.company.Server;
tableLogOnInfo.ConnectionInfo.DatabaseName = Menu.company.CompanyDB;
//tableLogOnInfo.ConnectionInfo.UserID = Menu.company.UserName;
//tableLogOnInfo.ConnectionInfo.Password = Menu.company.Password;
tableLogOnInfo.ConnectionInfo.UserID = Menu .company.DbUserName;
tableLogOnInfo.ConnectionInfo.Password = Menu.company.DbPassword;
tableLogOnInfo.ConnectionInfo.IntegratedSecurity = false ;
table.ApplyLogOnInfo(tableLogOnInfo);
table.Location = Menu.company.CompanyDB + ".dbo." + table.Name.ToString();
}
foreach (CrystalDecisions.CrystalReports.Engine.Table table in report.Database.Tables)
{
TableLogOnInfo tableLogOnInfo = table.LogOnInfo;
MessageBox.Show(tableLogOnInfo.ConnectionInfo.ServerName);
MessageBox.Show(tableLogOnInfo.ConnectionInfo.DatabaseName);
MessageBox.Show(tableLogOnInfo.ConnectionInfo.UserID);
MessageBox.Show(tableLogOnInfo.ConnectionInfo.Password.ToString());
MessageBox.Show(tableLogOnInfo.ConnectionInfo.IntegratedSecurity.ToString());
//table.ApplyLogOnInfo(tableLogOnInfo);
//table.Location = Menu.company.CompanyDB + ".dbo." + table.Name.ToString();
}
report.SetDataSource(matable);
report.SetDatabaseLogon(Menu.company.DbUserName, Menu.company.DbPassword);
PrinterSettings settings = new PrinterSettings();
PrintDialog pdialog = new PrintDialog();
pdialog.PrinterSettings = settings;
pdialog.AllowPrintToFile = true;
pdialog.AllowSomePages = true;
pdialog.UseEXDialog = true;
// ParameterFields parameterFields = report.ParameterFields;
//report.SetParameterValue(0, this.ComboBox0.Value);
//report.SetParameterValue(1, EditText1.Value.ToString());
//report.SetParameterValue(2, get_codebarre_dessin());
report.SetParameterValue(2, this.ComboBox0.Value);
report.SetParameterValue(1, EditText1.Value.ToString());
report.SetParameterValue(0, get_codebarre_dessin());
report.PrintOptions.PrinterName = ComboBox1.Value;
//report.PrintToPrinter(settings, new PageSettings() { }, false);
report.PrintToPrinter(1, true, 1, System.Convert.ToInt32(EditText0.Value));
maconnexion.Close();
}
catch (LogOnException engEx)
{
MessageBox.Show("Incorrect Logon Parameters. Check your user name and password." + engEx.ErrorID);
}
catch (DataSourceException engEx)
{
MessageBox.Show("An error has occurred while connecting to the database.");
}
catch (EngineException engEx)
{
MessageBox.Show(engEx.Message);
}