Tuesday, June 16, 2009

Logon failed on Crystal Report

Error : Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user 'UserXXX'. SQL State: 42000 Native Error: Error in File E:\TEMPSY~1\Tmp\temp_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.rpt: Unable to connect: incorrect log on parameters.

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,, 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.EnableDatabaseLogonPrompt = false;
crystalViewer.EnableParameterPrompt = false;

protected void btnPrint_Click(object sender, EventArgs e)
litXXX.Text = "";

ReportDocument rd = new ReportDocument();

ParameterDiscreteValue value = new ParameterDiscreteValue();
value.Value = Period;
ParameterValues parameterValuesPriod = new ParameterValues();

value = new ParameterDiscreteValue();
value.Value = Convert.ToByte(Semester);
ParameterValues parameterValuesSem = new ParameterValues();

ParameterField parameterField = rd.ParameterFields[0];
parameterField.DefaultValues = parameterValuesPriod;
parameterField.CurrentValues = parameterValuesPriod;

parameterField = rd.ParameterFields[1];
parameterField.DefaultValues = parameterValuesSem;
parameterField.CurrentValues = parameterValuesSem;

crystalViewer.ReportSource = rd;

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

<asp:literal id="litXXX" runat="server"></asp:literal>

<asp:button id="btnPrint" runat="server" text="Print Report" onclick="btnPrint_Click" />



  1. 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

  2. Hi, so you're the blogger of "What's a coder?" :P

    I 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".

  3. 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?

  4. Ah 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

    The "pre" tags is indeed not too good, but can't help, still too busy to try the SyntaxHighlighter ^^ Will try it some time

  5. [In English]
    Hey... 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 (); "

  6. I understand Englis ^^ Thank you for the comment. I remember that I actually tried using:
    - 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



Related Posts

Dual Axis not Working in Tableau

Problem : When creating chart with Dual Axis, Synchronize Axis is disabled and cannot be clicked. Cause : Tableau identified this as ...

About Me

My photo
Is an ordinary unNoticed man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing. I like English and Chinese language, and know a little about them. Hence, for me, most things can best be expressed in Chinese, some in English, and the rest in others ^^

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts



Follow by Email