+ Reply to Thread
Results 1 to 3 of 3

ADODB Connection String

  1. #1
    Registered User
    Join Date
    11-30-2006
    Posts
    15

    ADODB Connection String

    All,

    I have searched the Internet, and this forum, and have tried soo many attempts at this, however i am having no luck.

    I am trying to call an INSERT stored Procedure, from VBA6.5 in Excel to SQLServer Express 2005.

    I have created an ODBC connection called DevOH, and using the following few lines a can retrive data.
    I have replaced my userID with 'aa' and the workstationID with 'bb'

    ##################################################

    Dim qt As QueryTable
    Dim sqlstring As String
    Dim connString As String
    sqlstring = "SELECT View1.Column1, View1.Column2 FROM View1"
    connString = "ODBC;DSN=DevOH;Description=Development Overheads;UID=aa;APP=Microsoft® Query;WSID=bb;DATABASE=Dev OH;Network=DBNMPNTW"

    With ActiveSheet.QueryTables.Add(Connection:=connString, Destination:=Range("A1"), Sql:=sqlstring)
    .Refresh False
    End With

    ###################################################

    The above works fine,

    I am now having problems trying to execute the INSERT Procedure, I have the code below, again have replaced my Workstation(Express Server) with 'bb' for consistency.

    ###################################################
    Dim cn As ADODB.Connection
    Dim cmd As ADODB.Command
    Dim connString As String

    Set cn = New ADODB.Connection
    Set cmd = New ADODB.Command

    connString = "Driver={SQLServer};Server=bb\IANSDB;Database=Dev OH;Trusted_Connection=True;"

    cn.Open connString
    cmd.ActiveConnection = cn
    cmd.CommandText = "IC_InsertIntoTable1"
    cmd.CommandType = adCmdStoredProc

    cmd.Parameters("@Col1") = Range("B2").Value
    cmd.Parameters("@Col2") = Range("B3").Value

    cmd.Execute

    cn.Close
    ###################################################

    The error message i recieve is

    #Run-time error '-2147467259(80004005)': Data source name not found and no default driver specified#

    When i hit debug it's on the cn.Open connString line, i just can't seem to format my connection string properly, and help or advice is greatly appreciated.

    Ian

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302
    The exact syntax depends slightly on your provider - see here for a comprehensive list.

  3. #3
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    See http://www.connectionstrings.com/

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1