Link to home
Start Free TrialLog in
Avatar of pensiongenius
pensiongeniusFlag for United States of America

asked on

ODBC connection on Windows Server 2008 and Word Merge Issues


This might be a complicated one to explain...

I have a custom application written in vb.net that has a button that when clicked launches word, and merges some fields from a SQL database using an ODBC connection. I have attached a sample of the merge code for reference but that works fine.  

The problem is the ODBC connection.  We store the ODBC connection and the credentials in the app.config file and there is a copy of the SystemDSN / ODBC connector on each machine which gets installed through group policy.  

Recently we have had remote users who connect via terminal server to use this application.  They all connect to a machine running windows server 2008 R2 Enterprise.  When they attempt to run the merge they get a dialog box asking for the SQL password (even though the password is in the System DSN).  Even if the correct password is put in the merge fails.  This only occurs on the Windows Server 2008 machine.  This can be resolved by logging in as each user and creating a user DSN identical to the System DSN that is currently in place.  This is a growing problem as we have more and more remote users needing the system.  

The only current solutions are:  

1. Continue to create individual user DSN's (time consuming)

or

2. Have each user log into a separate Windows 7 machine because Windows 7 doesn't have this problem but Windows 7 can have only one remote user at a time.  This is not feasible because of the cost of individual machines and the growing number or remote users.

We have looked into creating the user DSN via group policy but that apparently is not an available feature in Windows Server.  What I am asking is does anyone know why Windows 2008 Server requires a user DSN to let MS Word connect to SQL via ODBC?  

I am guessing it is a security setting of some sort but I don't know where to begin to look.  Ideally I need the server to behave like Windows 7 where only the system DSN is necessary to merge.

Other relevant facts:  

Operating System:       Windows Server R2 2008
SQL Version :             SQL Server 2008 R2
MS Word Version :       2010

All latest updates and patches applied on a regular basis.

I realize I will probably need to expand as the experts ask follow up questions but I will monitor this question closely and try to respond quickly during normal business hours PST.

Dim oApp As Object = Nothing
        Dim oDoc As Object = Nothing
        Try
            oApp = CreateObject("Word.Application")
            oDoc = CreateObject("Word.Document")
        Catch ex As Exception
            kryptonmessagebox.Show(ex.Message)
        End Try

        Dim FullDocPath As String = Me.strDocPath & Me.strDocumentName

        If var_DoNotKillWord = True Then

        Else
            Try
                If Not fKillProcess("winword") Then
                    'kryptonmessagebox.Show("Could not close winword")
                End If
                If Not fKillProcess("winword") Then
                    'kryptonmessagebox.Show("Could not close winword")
                End If
            Catch ex As Exception

            End Try
        End If


        Dim intOffset As Single = 0
        Try
            'Start a new document in Word
            oApp = CType(CreateObject("Word.Application"), Word.Application)

            Try
                oDoc = oApp.Documents.Open(CType(FullDocPath, System.Object), False, True, False, , , True, , , Word.WdOpenFormat.wdOpenFormatDocument, , True)
            Catch MyException As System.Exception

                CType(oApp, Word.Application).Quit()
                oApp = Nothing
                Return False
                Exit Function
            End Try

            oApp.Visible = True

            Application.DoEvents()
            ' Do the Merge
            oApp.DisplayAlerts = False
            Dim TestStrings As New StringBuilder
            TestStrings.Append("With oDoc.MailMerge" & vbCrLf)
            'Added by Tom Harris Jan 2010 to add default styles and font size

            With oDoc.Styles(wdStyleNormal).Font
                .Name = "Arial"
                .Size = 10
                .Bold = False
                .Italic = False
                .Underline = wdUnderlineNone
                .UnderlineColor = wdColorAutomatic
                .StrikeThrough = False
                .DoubleStrikeThrough = False
                .Outline = False
                .Emboss = False
                .Shadow = False
                .Hidden = False
                .SmallCaps = False
                .AllCaps = False
                .Color = wdColorAutomatic
                .Engrave = False
                .Superscript = False
                .Subscript = False
                .Spacing = 0
                .Scaling = 100
                .Position = 0
                .Kerning = 0
                .Animation = wdAnimationNone
            End With

            With oDoc.MailMerge

                'View the Sql Statement for testing purposes
                Dim FullSql As String = var_SqlStatementPart1 & " " & var_SqlStatementPart2
                TestStrings.Append(FullSql & vbCrLf)
                TestStrings.Append(var_DataConnectionFilePath & vbCrLf)
                TestStrings.Append(var_ConnectionString & vbCrLf)
                TestStrings.Append(SqlStatementPart1 & vbCrLf)
                TestStrings.Append(FullDocPath & vbCrLf)

                Dim SQLString2 As String = ""







                Try
                    .OpenDataSource(Name:= _
                   var_DataConnectionFilePath _
                   , ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, _
                   AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
                   WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
                   Format:=wdOpenFormatAuto, Connection:= _
                   var_ConnectionString _
                    , SQLStatement:=SqlStatementPart1, SQLStatement1:=SqlStatementPart2, SubType:= _
                   Word.WdMergeSubType.wdMergeSubTypeWord)
                    .Destination = Word.WdMailMergeDestination.wdSendToNewDocument
                    .SuppressBlankLines = True
                Catch ex As Exception
                    kryptonmessagebox.Show(ex.Message)
                End Try



                With .DataSource
                    .FirstRecord = Word.WdMailMergeDefaultRecord.wdDefaultFirstRecord
                    .LastRecord = Word.WdMailMergeDefaultRecord.wdDefaultLastRecord
                End With
                Try
                    .Execute(Pause:=False)
                Catch ex As Exception

                End Try


            End With

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ayman Bakr
Ayman Bakr
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pensiongenius

ASKER

Thanks for the help, it is getting us in the right direction but we aren't coming back to this issue for a while so I am awarding points for now and will re-visit it when company priorities allow me to.