Forum Discussion

thexder1's avatar
thexder1
Contributor
13 years ago

jscript will not connect to database

I am trying to run some scripts that I made for running a queries on a database. I am using the correct login information and can connect to the database using other methods like the Microsoft SQL Server Management Studio, but when I run the script it just says SQL Server does not exist or access denied.



Here is what I have for my connection string.




Data Source=<sql server>; Provider=SQLOLEDB; uid=<username>; pwd=<password>


8 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    What is the context of how that connection string is used?  Can you post the script code itself where you are attempting the connection?

  • Basically I am just trying to check if a client exists in a database table. I found that I was able to get it to connect succesfully usng DSN connection, but I do not want to have to use that.



    function
    checkDatabase(client) {



    var connectionString = "Data Source=<sql server>; Provider=SQLOLEDB; uid=<username>; pwd=<password>; database=<databasename>";



    var dbconn = new ActiveXObject("ADODB.Connection");



    try {

    dbconn.Open(connectionString);



    var queryStr = "SELECT ClientName FROM Clients WHERE ClientName = "+client;



    var results = dbconn.Execute(queryStr);



    }



    finally {



    dbconn.Close;



    }



    return results;



    }


  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Okay... I hate to ask silly questions... but your connection string... are you ACTUALLY putting in <sql server> for the server name, or are you replacing that with your actual SQL server name?
  • I am replacing that with the server name, also replacing <username> with my username, <passsword> with my password and so on.
  • The error I get says SQL server does not exist or access denied. I can connect using the exact same settings when I use DSN for the database connection.
  • It's a while since I used (or understood) my SQL scripts but presuming it's not just a typo in your parameters, try adding an extra empty parameter in the connection line, i,e:



    var dbconn = new ActiveXObject("ADODB.Connection", "");