05 May 2007

Accessing CRM database from JScript

Here's the code how to accesss CRM database via JScript!


//initial connection
var connection = new ActiveXObject("ADODB.Connection");
var connectionString = "Provider=SQLOLEDB;Server=_db;Database=_mscrm;Integrated Security=sspi";
//open connection
connection.Open(connectionString);
//query string
var query = "SELECT name FROM FilteredAccount";
//create a ADO object
var rs = new ActiveXObject("ADODB.Recordset");
//open connection
rs.Open(query, connection, 1, 2);
rs.moveFirst();
var values = "";
//read data
while (!rs.eof)
{
values += rs.Fields(0).Value.toString() + " ";
rs.moveNext();
}
//close connection
connection.Close();
//alert value
alert(values);

4 comments:

  1. Anonymous7:14 am

    I am getting one error:

    safety setting on this computer prohibit accessing a data source on another domain

    ReplyDelete
  2. Regarding the error that Anonymous encountered "safety setting on this computer prohibit accessing a data source on another domain", this is an IE setting. In your browser go to Tools -> Options -> Security Tab -> Custom Level. Find the following option in the MISC section: Access data sources across domains and set to either Prompt or Enabled.

    ReplyDelete
  3. Hi,

    Thanks in advence for all your posts that are really usefull.

    I want to ask if is possible to use in a Jscript an Ado.Command Object to run a Stored Procedures.
    I have tried to do it but i got a message error that "automation server cannot created this object type"

    ReplyDelete