locked
mssql connection with vbscript - error RRS feed

  • Question

  • http://gallery.technet.microsoft.com/scriptcenter/a6a9d2a4-705f-4e37-86db-33caca7473cb

    Im using above script but get and error.

    The setup is mssql express 2012

    DB name: testdb
    DB user: testusr
    pass: Test12345
    Server: testsrv

    From another mashine could i fine connect to the server with server management studio with above info:

    Servername: testsrv\sqlexpress
    Auth: SQL Server Authentication
    Login: testusr
    Pwd: Test12345

    I have updatet the script with my info:

    Const adOpenStatic = 3 
    Const adLockOptimistic = 3 
     
    Set objConnection = CreateObject("ADODB.Connection") 
    Set objRecordSet = CreateObject("ADODB.Recordset") 
     
    objConnection.Open _ 
        "Provider=SQLOLEDB;Data Source=testsrv/sqlexpress;" & _ 
            "Trusted_Connection=Yes;Initial Catalog=testdb;" & _ 
                 "User ID=testusr;Password=Test12345;" 
     
    objRecordSet.Open "SELECT * FROM [testdb].[dbo].[Persons]", _ 
            objConnection, adOpenStatic, adLockOptimistic 
     
    objRecordSet.MoveFirst 
     
    Wscript.Echo objRecordSet.RecordCount 

    Get this error:

    Line 7, char 1

    [dbnetlib][connectionopen (Connect()).]SQL Server does not exist or access denied.

    code. 80004005

    Source: Microsoft OLE DB Provider for SQL Server


    Helpdesk Supporter



    • Edited by LongQuo Friday, March 7, 2014 2:28 PM
    Friday, March 7, 2014 1:47 PM

Answers

  • Remove Trusted:

     objConnection.Open   "Provider=SQLOLEDB.1;Password=12345;Persist Security Info=True;User ID=tessuser;Initial Catalog=testdb;Data Source=testsvr"


    ¯\_(ツ)_/¯

    • Marked as answer by LongQuo Monday, May 12, 2014 1:14 PM
    Friday, March 7, 2014 3:16 PM