Forum Discussion

NisHera's avatar
NisHera
Valued Contributor
10 years ago

Connecting to SQLServer 2012

Hi,

I'm trying to connct to SQLServer data base but failed

my basic script is something like this




Conn= Sys.OleObject("ADODB.Connection") ;


Conn.string = "MyString";


Conn.Open();


Conn.Execute("MyQuery",RowCount);


Conn.Close();



For "MyString" I have used following upto now...





  • 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MachineName\SQLEXPRESS2012;'


  • 'Provider=SQLNCLI11;Server=MachineName\SQLEXPRESS2012;Database=MyDB;Trusted_Connection=yes;'


  • 'Driver={SQL Server Native Client 11.0};Server=myServerName\SQLEXPRESS2012;Database=MyDB;Trusted_Connection=yes;'


  • 'Provider=SQLNCLI11;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDB;Data Source=MachineName\SQLEXPRESS2012;'




But no success ...is anybody out there can help me..?

With first string returns empty 

rest give something....... Named Pipes Provider: Could not open a connection to SQL Server [53]. 

 



  • Ravik's avatar
    Ravik
    Super Contributor
    nishnatha herath



    You can use a alternative way but its machine and environment dependant.

    You can create DSN (data source Name) by following below steps



    1- Strart >> Control Panel >> Administrative Tool >> Data Source(ODBC) -Double click>> Add >> Select SQL Server >> Name - Enter Name >> Description - Enter Description >> Server - Enter Server IP address >> Next >> Select With SQL Server authentication using a login ID and Password >> Enter Login ID and Password >> Next
  • NisHera's avatar
    NisHera
    Valued Contributor
    Hi Tania,

    tanks for link , ofcource I got those strings from there.

    It was not a problem of connection string as I throught.

    (The first string works and connects) 

    But connection .execute does not work.

    Found I have to create ADO command object and set active connection equles to ADODB  connction.



  • NisHera's avatar
    NisHera
    Valued Contributor
    Thanks Ravi,

    But this is a part of my test frame work.

    Hence prefer machine/envirenment independent way