Cannot connect to database

Stimulsoft Reports.NET discussion
Post Reply
jellis
Posts: 22
Joined: Wed Jun 27, 2007 5:28 am
Location: United Kingdom

Cannot connect to database

Post by jellis »

Hi,

I have a problem when trying to clear the database and add a new one at runtime. The error that we recieve is that the 'Login failed for user....'
On our development machines, the code works perfectly, but the release build errors. The main application uses the same connection string as the one passed into stimulsoft.
We've stubbed the code to checked that the connection string is decrypted correctly before passsing to stimulsoft.

Here is the code;

Code: Select all

Private Sub RenderReport(ByVal ReportName As String)


        Dim Report As New StiReport
        ''----load the report
        Report.Load(ReportName)
        Report.Compile()

        '----wind through the report varibales & see if we can find project id
        '----if we can, populate it with selectedProjectGUID if we need to
        Dim v As StiVariable

        If useProjectId Then
            For Each v In Report.Dictionary.Variables
                If v.Name = "ProjectId" And useProjectId Then
                    Report("ProjectId") = selectedProjectGUID.ToString
                End If
            Next
        End If
        



        '----get the current connection string
        Dim strConn As String = DataAccess.DBUtilities.GetDecryptedDBConnection()

        '----clear the data dictionary to make a new connection using the current connection string
        '----Clear the list of databases
        Report.Dictionary.Databases.Clear()

        '----Add the database and specify its name and the connection string
        Report.Dictionary.Databases.Add(New StiSqlDatabase("C22", strConn))

        

        '----render the report
        Report.Render()

        '----show the report in the preview control
        Me.stiPreview.Report = Report

End Sub
and here is a stack trace of the error

Stack Trace:
----------------------
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Stimulsoft.Report.Dictionary.StiSqlAdapterService.OpenConnection(IDbConnection connection, StiData data, StiDictionary dictionary)
at Stimulsoft.Report.Dictionary.StiSqlAdapterService.ConnectDataSourceToData(StiDictionary dictionary, StiDataSource dataSource, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDataSource.Connect(StiDataCollection datas, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDataSourcesCollection.Connect(StiDataCollection datas, Boolean loadData)
at Stimulsoft.Report.Dictionary.StiDictionary.Connect(Boolean loadData)
at Stimulsoft.Report.Render.StiRenderProvider.ConnectToData(StiReport report)
at Stimulsoft.Report.Render.StiRenderProvider.Render(StiReport report, StiRenderState state)
at Stimulsoft.Report.StiReport.Render(StiRenderState renderState)
at Stimulsoft.Report.StiReport.Render()
at CITSQL.ReportPreview.RenderReport(String ReportName)
at CITSQL.ReportPreview.gridReportList_DoubleClick(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
at C1.Win.C1FlexGrid.C1FlexGridBase.OnDoubleClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at C1.Win.C1FlexGrid.Util.BaseControls.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Message:
----------------------
Cannot open database "C22" requested by the login. The login failed.
Login failed for user 'DOMAIN\username' '-----this obviously displays the actual domain and user name.

Target Site:
----------------------
Void OnError(System.Data.SqlClient.SqlException, Boolean)

Source:
----------------------
.Net SqlClient Data Provider
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Cannot connect to database

Post by Edward »

Hello.

Could you say which operation system is installed on that problem machine, please?

Also please change the report.Render() command to Report.Design() and try to preview the report from the Designer.

Thank you.
jellis
Posts: 22
Joined: Wed Jun 27, 2007 5:28 am
Location: United Kingdom

Cannot connect to database

Post by jellis »

Hi Edward,

It's been tested on 2 machines, one running XP SP2, and the other running Vista Business.
If we change render to design & render from there it works ok. It only fails if we go straight to render.

Thanks,

Jon.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Cannot connect to database

Post by Edward »

Hello, Jon.

I have got an idea about your code.

There is a Compile command and after that command you deleted all Databases and added a new DataBase. It is not a correct way.

You have to delete old Database and add that new Database for not compiled report (before calling Compile()) or just add new databases to the report after compilation (in that case there must be no database registered in template).

The code might be modified in the following way:

Code: Select all

Dim Report As New StiReport
        ''----load the report
        Report.Load(ReportName)

        '----clear the data dictionary to make a new connection using the current connection string
        '----Clear the list of databases
        Report.Dictionary.Databases.Clear()

        Report.Compile()

        '----wind through the report varibales & see if we can find project id
        '----if we can, populate it with selectedProjectGUID if we need to
        Dim v As StiVariable

        If useProjectId Then
            For Each v In Report.Dictionary.Variables
                If v.Name = "ProjectId" And useProjectId Then
                    Report("ProjectId") = selectedProjectGUID.ToString
                End If
            Next
        End If
       
        '----get the current connection string
        Dim strConn As String = DataAccess.DBUtilities.GetDecryptedDBConnection()

        '----Add the database and specify its name and the connection string
        Report.Dictionary.Databases.Add(New StiSqlDatabase("C22", strConn))
       
        '----render the report
        Report.Render()

        '----show the report in the preview control
        Me.stiPreview.Report = Report
Thank you.
jellis
Posts: 22
Joined: Wed Jun 27, 2007 5:28 am
Location: United Kingdom

Cannot connect to database

Post by jellis »

Thanks Edward for the prompt response.
I have changed the code as suggested, and now there is no DB error BUT... now the report has no data in it? I just get a single blank page.
Any thoughts?

Also since implementing that change, both the development machines and compiled version behave the same way - big blank page.

Jon.
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Cannot connect to database

Post by Edward »

Sorry, one thing must be done for synchronization of the DataStore content and the Dictionary. To call method Synchronize().
Also that code must be applied for the compiled report:

Code: Select all

        '----Add the database and specify its name and the connection string
        Report.CompiledReport.Dictionary.Databases.Add(New StiSqlDatabase("C22", strConn))

        Report.Dictionary.Synchronize()
       
        '----render the report
        Report.Render()

        '----show the report in the preview control
        Me.stiPreview.Report = Report
Also the 'Name In Source' parameter must be set in 'C22' for the DataSources in Dictionary.

Thank you.
jellis
Posts: 22
Joined: Wed Jun 27, 2007 5:28 am
Location: United Kingdom

Cannot connect to database

Post by jellis »

Thanks Edward,

That sorted it fine.

J. :biggrin:
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Cannot connect to database

Post by Edward »

Good news!

Please let us know if any help is required.

Thank you.
Post Reply