Results 1 to 1 of 1

Connecting Excel worksheet to SQL

Threaded View

  1. #1
    Registered User
    Join Date
    02-01-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Connecting Excel worksheet to SQL

    Hello All,

    I am trying to connect to the sql server 2005 via Excel 2007.

    Dim Cn As ADODB.Connection
        Dim ServerName As String
        Dim DatabaseName As String
        Dim TableName As String
        Dim UserID As String
        Dim Password As String
        Dim rs As ADODB.Recordset
        Dim RowCounter As Long
        Dim ColCounter As Integer
        Dim NoOfFields As Integer
        Dim StartRow As Long
        Dim EndRow As Long
        Dim LastRow As Long
        
        Set rs = New ADODB.Recordset
         
         
        ServerName = "TestServer" ' Enter your server name here
        DatabaseName = "finance" ' Enter your  database name here
        TableName = "dbo.Add_Bill" ' Enter your Table name here
        UserID = "" ' Enter your user ID here
         ' (Leave ID and Password blank if using windows Authentification")
        Password = "" ' Enter your password here
        NoOfFields = 32 ' Enter number of fields to update (eg. columns in your worksheet)
        StartRow = 2 ' Enter row in sheet to start reading  records
        LastRow = ActiveSheet.UsedRange.Rows.Count ' ActiveSheet.UsedRange.Rows.Count
        
        EndRow = LastRow  ' Enter row of last record in sheet
         
        Dim shtSheetToWork As Worksheet
        Set shtSheetToWork = ActiveWorkbook.Worksheets("Data")
         '********
         
        Set Cn = New ADODB.Connection
        'Cn.Open "Driver={SQL Server};Server=" & ServerName & ";Database=" & DatabaseName & _
        '";Uid=" & UserID & ";Pwd=" & Password & ";"
       Dim strConn As String
       strConn = "Network Library=DBMSSOCN;PROVIDER=SQLOLEDB;"
       strConn = strConn & "DATA SOURCE=testserver;INITIAL CATALOG=finance;"
       strConn = strConn & " Uid=********;Pwd=********;"
       Cn.ConnectionString = strConn
       'Conn.ConnectionString = strConn
       Cn.Open
    I get the error:
    "Run time error '-2147467259 (80004005)':[DBNETLIB][ConnectionOpen (Connect()). ]Specified sql server not found."

    Any help is applreciated.
    Thanks!!
    Last edited by usr123; 02-01-2010 at 05:45 AM.

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