Solution : Open the report, then Verify Database, using the login used while deploying!
This error takes me a lifetime to solve. It actually doesn't make sense to verify database for a report using the real login while deploying. That means all reports created while developing will have to be verified. The login info should be able to be set programmatically.
In my case, there are already some pages on the web that use similar reporting. I've printed the report using the same code, but no matter how I try, none works. I've tried a lot of ways to make it print, but all to no avail.
At last, I verify the report using the login used while deploying, then re-upload it. It works fine. phew -.-""""""
I set the login information for the report from web.config:
<!--<add key="ConnectionInfo" value="Database_name, server, user, password">-->
<add key="ConnectionInfo" value="DB1, 10.20.20.9, steven, steven"||/add>
Here's the .cs code I use for the report, and it should work fine, I guess.
private void BindConnectionInfo()
{
ConnectionInfo connectionInfo = new ConnectionInfo();
string conInfo = SystemConfiguration.ConnectionInfo; //get from web.config
connectionInfo.DatabaseName = conInfo.Split(',')[0].Trim();
connectionInfo.ServerName = conInfo.Split(',')[1].Trim();
connectionInfo.UserID = conInfo.Split(',')[2].Trim();
connectionInfo.Password = conInfo.Split(',')[3].Trim();
TableLogOnInfo t = new TableLogOnInfo();
t.ConnectionInfo = connectionInfo;
if (crystalViewer.LogOnInfo.Count == 0)
{
crystalViewer.LogOnInfo.Add(t);
}
crystalViewer.EnableDatabaseLogonPrompt = false;
crystalViewer.EnableParameterPrompt = false;
}
protected void btnPrint_Click(object sender, EventArgs e)
{
litXXX.Text = "";
BindConnectionInfo();
ReportDocument rd = new ReportDocument();
rd.Load(Server.MapPath("../../Report/report_name.rpt"));
ParameterDiscreteValue value = new ParameterDiscreteValue();
value.Value = Period;
ParameterValues parameterValuesPriod = new ParameterValues();
parameterValuesPriod.Add(value);
value = new ParameterDiscreteValue();
value.Value = Convert.ToByte(Semester);
ParameterValues parameterValuesSem = new ParameterValues();
parameterValuesSem.Add(value);
ParameterField parameterField = rd.ParameterFields[0];
parameterField.DefaultValues = parameterValuesPriod;
parameterField.CurrentValues = parameterValuesPriod;
parameterField = rd.ParameterFields[1];
parameterField.DefaultValues = parameterValuesSem;
parameterField.CurrentValues = parameterValuesSem;
crystalViewer.ReportSource = rd;
crystalViewer.DataBind();
}
And here's the .aspx code:
script type="text/javascript">
<!--
function PrintPartsViewer()
{
var objWindow = window.open("about:blank", "print", "width=800, height=600, toolbar=no");
var strHtml = "<html>";
strHtml += "<head>";
strHtml += "</head>";
strHtml += "<body>";
var element = document.getElementById("divPrint");
strHtml += element.innerHTML;
strHtml += "</body>";
strHtml += "</html>";
objWindow.document.write(strHtml);
objWindow.document.close();
objWindow.print();
objWindow.close();
}
//-->
</script>
<asp:literal id="litXXX" runat="server"></asp:literal>
<asp:button id="btnPrint" runat="server" text="Print Report" onclick="btnPrint_Click" />
offtopic - Hello I've been reading your blog and I'm a programmer too, but right now I'm at rest in my programming days cause I'm addicted to blogging. Right now I'm interested in learning php and I want to make a blog about my php conquest and my experiences learning it. The question is how did you make those containers in your sourcecodes, searched it in google but still don't know the right term... thank you very much
ReplyDeleteHi, so you're the blogger of "What's a coder?" :P
ReplyDeleteI only play with the style in html. You can actually see it if you view the source on my page. I use the following style:
|pre style="border: 1px solid gray; overflow: auto; width: 97.5%; color: rgb(0, 153, 0); font-size: 85%; font-family: courier new;"|
PS: Change || to < and >
There are some options you can use to make it even prettier. You can use SyntaxHighlighter, usually used in wordpress. Or you can use Code Prettifier, made by Google. I myself prefer SyntaxHighlighter to Code Prettifier, since it's prettier using SyntaxHighlighter.
I had tried implementing both, but I failed, and haven't had spare time to try it again. If you want to know further about how to use it, just search using the keyword "SyntaxHighlighter" or "Code Prettifier".
thank you for the help man... you've been using "pre" tags for it, I've been using it too in my first blog but I wasted my time using it.. thanks for the tip, I'll be checkin SyntaxHiglighter later, BTW you program mainly on .NET?
ReplyDeleteAh yes, I mostly post about asp.net C#, since I'm using it a lot now. Though I used to learn and use some programming languages, like C, C++, Visual Basic, PHP, ASP, JSP, Java... Wakakakak. I know more on Visual Basic, actually. So, I'll also post some codes in Visual Basic :D
ReplyDeleteThe "pre" tags is indeed not too good, but can't help, still too busy to try the SyntaxHighlighter ^^ Will try it some time
[In English]
ReplyDeleteHey... you can resolve with the follow steps:
-> Add in your code c# : rd.SetDatabaseLogon("user","password");
-> If you can't, update the conection of your report to OLEDB.
-> If doesn't work with two steps up, then try give permission (Read / Write) in temp folder (C:\Windows\Temp and/or C:\Temp), to user IIS_IUSR
Try, with me worked perfectly!
One hint: For pass parameters, use the function "rd.SetParameterValue("@Test", "Value");"
And remove the follow code:
" connectionInfo.DatabaseName = conInfo.Split(',')[0].Trim(); connectionInfo.ServerName = conInfo.Split(',')[1].Trim(); connectionInfo.UserID = conInfo.Split(',')[2].Trim(); connectionInfo.Password = conInfo.Split(',')[3].Trim();"
[Em portugues]
Ei ... você pode resolver com os seguintes passos:
-> Adicionar no seu código C #: rd.SetDatabaseLogon ( "user", "password");
-> Se não for possível, atualize a conexão de seu relatório para OLEDB.
-> Se não funcionar com dois passos acima, tente dar permissão (Read/Write) na pasta Temp (C:\Windows\Temp e/ou C:\Temp), para o usuário IIS_IUSR;
Não custa tentar, comigo funcionou perfeitamente!
Uma dica: Para passar parâmetros, use a função "rd.SetParameterValue("@teste","Value");"
E remover o seguinte código:
"ConnectionInfo.DatabaseName = conInfo.Split (',')[ 0]. Trim (); connectionInfo.ServerName = conInfo.Split (',')[ 1]. Trim (); connectionInfo.UserID = conInfo.Split ( ' , ') [2]. Trim (); connectionInfo.Password = conInfo.Split (',')[ 3]. Trim (); "
I understand Englis ^^ Thank you for the comment. I remember that I actually tried using:
ReplyDelete- rd.SetDatabaseLogon("user","password");
- rd.SetParameterValue("@Test", "Value");
None worked though. Otherwise, I wouldn't have used the user and password used while deploying :)
I don't remember whether I tried changing the connection to OLEDB... hehehe