choosechrist 0 Newbie Poster

I had started a similar thread earlier, but i did not get any explanations. I hope i am not crossing any line by repeating.

My problem is this. every form in my application accesses the database through a connection string within the startup(Login) form. the login inturn gets the user parameters from an xml file.

Public Sub ReadfromXML()
        Dim I As Integer
        Dim ServerName As String
        Dim DatabaseName As String
        Dim UID As String
        Dim PWD As String

        For I = 0 To 2
            Dim doc As XmlDocument = New XmlDocument()

            Dim root As XmlElement = doc.DocumentElement

            ServerName = root.Attributes.Item(0).Value
            DatabaseName = root.Attributes.Item(1).Value
            UID = root.Attributes.Item(2).Value
            PWD = root.Attributes.Item(3).Value

            cnString = "server=" & ServerName & ";database=" & DatabaseName & ";User ID=" & UID & ";Password=" & PWD & ""

            CN = New SqlConnection

                With (CN)
                    If .State = ConnectionState.Open Then .Close()

                    .ConnectionString = cnString
                    Exit For
                End With
            Catch ex As Exception
                If Err.Number = 5 Then
                    MsgBox("Cannot connect to server. Make sure that the server is running. " & vbCrLf & vbCrLf & "Otherwise please check for the configuration.", MsgBoxStyle.Exclamation)

                    'Dim DBPath As New frmDBPath

                End If
            End Try
        Next (I)
    End Sub

now i am using crystal reports and i want the rpt files to access this connection either through the xml file or through the login form.right now what i am doing is, i created a normal form, inserted a crystal report viewer and within that form i put the code

cmd.Connection = thisConnection
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "Select * from ATA_Pending"
        da.SelectCommand = cmd
        da.Fill(ds, "test")
        Dim strpath As String
        Dim strpath1 As String
        strpath = Application.StartupPath
        strpath1 = strpath.Remove(strpath.Length - 9, 9) + "ATAP.rpt"

        Dim cr As New ReportDocument


        Me.crv1.ReportSource = cr

the rpt file i manually take database expert and create a connection "sql native client" . this works on a normal basis. but if i run it anywhere else(the published copy), the reports wont open.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.