Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Please Help Error:Connection for Source DataConnection failed because the environment is not trusted

Avatar

Level 2

Iam getting this error while trying to load the PDF form from SQl server 2005 using Oledb driver for SQL server - Error is " Connection for Source DataConnection failed because the environment is not trusted".

This is my connection string -

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=Mashreq;Data Source=ADOBE-8D78D8E4E;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=ADOBE-8D78D8E4E;Use Encryption for Data=False;Tag with column collation when possible=False

Please help me

Thanks,

Vinod

2 Replies

Avatar

Level 2

Dear Jas, please find my below explanation.....

I created a variable(Insert Script Object) "Database" to write the script inside.

Below is the script I wrote inside the variable "Database" to connect and fetch data from SQl server 2005, where SQLSERVERUPDATECONNECTION is dsn connection to the sql server.

/**

* The name of the data connection defined in the form which is to be used as a template for the data

* connection created to execute SQL statements.

*/

var

ODBC_DATA_CONN

= "SQLSERVERUPDATECONNECTION";

/**

* Search the sourceSet model for a data connection with the specified name and return a reference to it.

* @param sDataConnName Name of the data connection sought.

* @param bClone If true and the data connection is found, a clone of the data connection will be returned.

* @return The data connection (or a clone) if found; null otherwise.

*/

function

GetDataConn(sDataConnName

, bClone)

{

var

oDataConnList = xfa.sourceSet.nodes; // this will be a list of <source> nodes

var

nCount = oDataConnList.length;

for

(var i = 0; i < nCount; i++)

{

var

oDataConnNode = oDataConnList.item(i); // this will be a <source> node

if

(oDataConnNode.className == "source" && oDataConnNode.name == sDataConnName)

return

bClone ? oDataConnNode.clone(1) : oDataConnNode;

}

return

null;

}

/**

* Convert the specified data connection to an empty connection ready to execute SQL statements. Essentially,

* this removes all non-pertinent nodes, leaving the <query> node under <command>, specifies that the command

* is an SQL query and sets the BOF and EOF actions to be "stay" (critical to SQL statements executing properly).

* @param oDCNode Reference to the data connection to convert. This expected to be a clone of the actual data

* connection or else the function will fail with a security exception.

* @return A reference to the <select> node in the data connection's <query> node or null if an error occurred.

*/

function PrepareForSQL(oDCNode)

{

// First, clean the data connection node itself to get rid of the unecessary <bind> nodes.

var nDCChildCount = oDCNode.nodes.length;

var oCommandNode = null;

for (var i = nDCChildCount - 1; i >= 0; i--) // reverse through the list since we're removing nodes

{

var oDCChildNode = oDCNode.nodes.item(i).clone(1);

if (oDCChildNode.className == "command")

{

// keep the <command> node for later

oCommandNode = oDCChildNode;

}

else if (oDCChildNode.className != "connect")

{

// We don't want to keep anything aside from the <command> and <connect> nodes.

oDCNode.nodes.remove(oDCChildNode);

}

}

// Then, remove all the nodes inside <command> except for <query>.

if (null == oCommandNode)

{

// We weren't able to find the <command> node >> something went wrong!

return null;

}

var nCommChildCount = oCommandNode.nodes.length;

var oQueryNode = null;

for (var i = nCommChildCount - 1; i >= 0; i--) // reverse throught the list since we're removing nodes

{

var oCommChildNode = oCommandNode.nodes.item(i).clone(1);

if (oCommChildNode.className == "query")

{

// remember this for later

oQueryNode = oCommChildNode;

}

else

oCommandNode.nodes.remove(oCommChildNode); // remove everything else

}

// Next, clean-up the <query> node, removing all children except for <select> (which contains the SQL query).

// Finally, specify that the query is an SQL statement.

if (null == oQueryNode)

{

// The new <query> node couldn't be found for some reason.

return null;

}

var nQueryChildCount = oQueryNode.nodes.length;

var oSelectNode = null;

var oRecordSetNode = null;

for (var i = nQueryChildCount - 1; i >= 0; i--) // reverse throught the list since we're removing nodes

{

var oQueryChildNode = oQueryNode.nodes.item(i).clone(1);

if (oQueryChildNode.className == "select")

{

// remember this for later

oSelectNode = oQueryChildNode;

}

else if (oQueryChildNode.className == "recordSet")

{

// remember this for later

oRecordSetNode = oQueryChildNode;

}

else

{

// anything else gets removed

oQueryNode.nodes.remove(oQueryChildNode);

}

}

oQueryNode.commandType = "text"; // specify that it's an SQL query

if (null == oRecordSetNode)

{

// We weren't able to obtain a reference to the <recordSet> node inside the <query> node.

// Since it's critical that its BOF and EOF actions be set properly, we can't proceed.

return null;

}

oRecordSetNode.bofAction = "stayBOF";

oRecordSetNode.eofAction = "stayEOF";

// At this point, the data connection node looks like this:

// <source name="DataConnection">

// ...

// <command>

// <query commandType="text">

// <select>...</select>

// <recordSet bofAction="stayBOF" eofAction="stayEOF" ... />

// </command>

// </source>

return oSelectNode; // return a reference to the <select>

}

/**

* Convenience function that calls the second verion of ExecSQL and defaults to "auto close".

* See the full version of ExecSQL below for more information.

*/

function ExecSQL(sSQL)

{

ExecSQL(sSQL, true);

}

/**

* Executes the specified SQL statement on a cloned version of the ODBC_DATA_CONN data connection.

* @param sSQL The SQL statement to execute. Can be insert, update, or delete. Select is not supported.

* @param bAutoClose If true, the data connection is closed automatically after being executed. Otherwise, the data connection

* remains open and a reference is returned.

* @return If bAutoClose is true, null is always returned. Otherwise, if the connection was successfully opened, the open data connection

* is returned. The caller is responsible to close it. This is useful when specifying a "select" query in order to iterate through the

* selected records. If an error occurs and bAutoClose was false, null is returned.

*/

function ExecSQL(sSQL, bAutoClose)

{

var oDC = GetDataConn(ODBC_DATA_CONN, true); // get a clone of the data connection (we must clone it prior to modifying it or else we'll get a security exception)

var oSelectNode = PrepareForSQL(oDC); // modify the cloned data connection to execute any SQL statement and get a reference to its <select> node

if (null != oSelectNode)

{

// We successfully converted the data connection into an "insert" connection. All we need to do now is set the SQL for the <query> node

// and open the data connection to get it to execute the query.

oSelectNode.value

=

sSQL;

// Enable this statement to peek at what the data connection's definition looks like now in the Acrobat JavaScript Console (Ctrl + J).

//console.println(oDC.saveXML("pretty"));

try

{

oDC.open();

// execute the data connection (and the SQL statement)

app.alert("Done");

}

catch

(e)

{

app.alert(e);

console.println(e);

oDC

=

null;

}

}

if

(null != oDC && bAutoClose)

{

oDC.close();

oDC

=

null;

}

return

oDC;

}

And, then in my update button click I am using the below script

Database.ExecSQL("UPDATE Mashreq_Customers SET FIRST_NAME = 'Jasmine' WHERE SERIAL_NO='1';")

And when loading the form using Microsoft OLEDB connection for SQL server – error : Connection for Source DataConnection failed because the environment is not trusted

And when loading the form using OLEDB Driver for odbc – loading is happening with our error. But on clicking update button –the code finished debugging without error. But when I checked the table, no updation is happening in the back end!

Please help me, or guide me to reach my target or help me by providing new approach to reach my target!

With Thanks,

Vinod