View Single Post
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Poppa Bear Poppa Bear is offline
external usenet poster
 
Posts: 4
Default OpenDataSource SQL Server xpress problem

Thanks a lot Peter. Have not had chance to try it yet - but will as soon as I
can. People like you are wonderful but it baffles me why I can't find any
explanation of these things on the Microsoft Help or elsewhere, and why are
all the examples for Access files and none (that I could find) for SQL Server
?. Maybe I'm looking in the wrong place. Are there any good books on the
subject ?

Yes I should have said that the Server is a localhost but you guessed that
correctly. Many thanks for your time and help. My partner is grateful as
well !!! Will let you know if it works or doesn't ! .
--
Poppa


"Peter Jamieson" wrote:

Typically you do not access the .mdf file directly, but via the SQL Server
database manager which in this case is probably running on your local
system. To do that from Word you provide either a .odc ("Office Data
Connection") file or a .udl "Universal Data Link" file, which in turn
contains the connection information.

..odc files can be created manually by clicking the New Source button in the
Open Data Source dialog, selecting the "Microsoft SQL Server" option, then
follow the dialogs. However, you can also try using a completely empty .odc
file (e.g. create an empty .txt file in Notepad, save it, and rename it to
empty.odc. Then (assuming you put that in c:\work) try

'' FOR SQL SERVER Express version

Dim sDBPath As String = "C:\WORK\empty.odc" '
**********************(C)

Dim strConnect As String = "Provider=SQLOLEDB.1;Data
Source=c7e6i3;Database=dbSQLEmpTest;Integrated Security=True;"

for the older SQL OLE DB provider

or maybe

Dim strConnect As String = "Provider=SQLNCLI;Data
Source=c7e6i3;Database=dbSQLEmpTest;Integrated Security=True;"

for the newer "Native Client".

For the Data Source parameter you will either need the machine name of the
server - if that is c7e6i3 then you may be OK, or that name + "\SQLEXPRESS",
e.g.

Data Source=c7e6i3\SQLEXPRESS

There may be more to it than that, but start there...

--
Peter Jamieson
http://tips.pjmsn.me.uk

"Poppa Bear" wrote in message
...
using :
VS 2005 SE 2 ............ NOT VSTO
Word 2003
Office Interop v 10
Word Interop v 10


Trying to Mailmerge Word 2003 Document with Database.
1. With ACCESS.mdb works fine (lines (A) and (B) below active (C) and
(D)
commented out

2. With SQL Server get message about failed to connect. (C) and (D) active
(A) and (B) commented out.

Using same Template file (CVSTemplate3.dot). Access and SQL server Xpress
DBs have same tables and data

Also get a dialog box about "Header Record Delimiters" telling me Data
fields and Data Records must be separated by delimiters. Haven't the
faintest
idea what this refers to (sorry) . Can someone help please ? The
connection
string for the SQL Server version is the same as I use in the main program
code to open the SQLServer Database - which works fine there, using
Windows
Authentification. Have trawled the MS website and others for info with no
success. You are my last hope ! Help --- Please !!

Code snippets :

Private Sub btnOpenWord_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOpenWord.Click
Dim wrdApp As Word.Application =
CType(CreateObject("Word.Application"), Word.Application)
Dim wrdDoc As Word.Document =
CType(wrdApp.Documents.Add("CVSTemplate3.dot", False,
Word.WdDocumentType.wdTypeDocument, True), Word.Document)

Dim sqlQuery As String = "SELECT * FROM [tblEmployees] WHERE
EmployeeLastName LIKE '" & "Jones" & "';"

'' For ACCESS version
'Dim sDBPath As String = "C:\WORK\DBTestEmp.mdb"
'*********************** (A)
'Dim strConnect = System.Type.Missing
'*********************** (B)

'' FOR SQL SERVER Express version
Dim sDBPath As String = "C:\WORK\dbSQLEmpTest.mdf" '
**********************(C)
Dim strConnect As String = "Data
Source=c7e6i3;Database=dbSQLEmpTest;Integrated Security=True;" '
*********************(D)

Try
With wrdDoc.MailMerge
.MainDocumentType =
Word.WdMailMergeMainDocType.wdFormLetters
.OpenDataSource(Name:=sDBPath, Connection:=strConnect,
SQLStatement:=sqlQuery)
.Destination =
Word.WdMailMergeDestination.wdSendToNewDocument
.Execute(Pause:=False)
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
wrdApp.Visible = True
End Sub
--
Poppa