Page 1 of 2

Off Beat Question - Javascript - SQL

PostPosted: Wed May 22, 2013 9:16 pm
by cdmmaui
Hello,

I was wondering if someone could help me with a problem connecting to MS SQL server from JavaScript code. The following code is failing at connection.Open(connectionstring);

SQL and IIS 6 are on two different server but on same network. I have opened firewall port 1433; what other items should I look at?

Thank you,

// Script...
<script>
function consignee() {

var consid = document.getElementById("consid").value;
var consname = document.getElementById("consname");

try
{
var connection = new ActiveXObject("ADODB.Connection");
}
catch(e)
{
alert("ADODB namespace not found.");
exit(0);
}

try
{
var connectionstring="Data Source=1.2.3.4;Initial Catalog=SQLDB;User ID=user_id;Password=password;Provider=SQLOLEDB";
connection.Open(connectionstring);
}
catch(e)
{
alert("Cannot connect to SQL DB.");
exit(0);
}

...

</script>

Re: Off Beat Question - Javascript - SQL

PostPosted: Wed May 22, 2013 9:55 pm
by Armando
Darrell:

Perhaps your Windows firewall?, just an idea.

Regards

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 12:22 am
by cdmmaui
Thank you, I did check that beforehand

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 8:01 am
by Antonio Linares
Darrell,

I would check the returned error description:

try
{
var connectionstring="Data Source=1.2.3.4;Initial Catalog=SQLDB;User ID=user_id;Password=password;Provider=SQLOLEDB";
connection.Open(connectionstring);
}
catch(e)
{
alert( e.message );
exit(0);
}

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 10:22 am
by ADutheil
Darrell,

can you log in with another tool? Did you choose the right location when created the user? Was your user created with the force change password option?

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 11:28 am
by cdmmaui
Hi Antonio,

Thanks, I got the following error and I am searching internet to find resolution.

"Safety settings on this computer prohibit accessing a data source on another domain."

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 2:03 pm
by Antonio Linares
Darrell,

This seems valid:
http://www.office-archive.com/58-ms-access/dc6711a5d25b9aa5.htm

This setting can be found on the Internet Options and the Security
Settings. Look under the Miscellaneous.
Access data sources across domains, needs to be enabled.
Please let me know if this helps or if I can be of further assistance.
Thank you for working with the Microsoft Newsgroups
Timothy P Macaulay, Microsoft Certified Professional

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 3:14 pm
by cdmmaui
Hi Antonio,

I was able to update the setting on my computer to resolve the problem. However, my concern now is that my customers will not want to change their setting. I am moving IIS6 to same server as MS SQL and will try to access via (local) instead of IP address. I hope this resolves requirement.

Sincerely,

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 3:26 pm
by Antonio Linares
Yes, good idea :-)

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 3:36 pm
by cdmmaui
Hi Antonio,

I moved IIS application to same server as SQL and used the following connection string and I am getting same response. Any idea on what I can do to resolve?

var connectionstring="Data Source=(local);Initial Catalog=XXXX;User ID=XXXXX;Password=XXXXX;Provider=SQLOLEDB";

Re: Off Beat Question - Javascript - SQL

PostPosted: Thu May 23, 2013 3:44 pm
by Antonio Linares
Have you tried to create a datasource from "Control Panel", "Administrative tools", "ODBC datasources" ?

It offers a "test" button that allows you to check the connection string

Re: Off Beat Question - Javascript - SQL

PostPosted: Fri May 24, 2013 6:50 pm
by cdmmaui
Hi Antonio,

The System DSN work fine and test works fine. However, when I try to access using the following connection string nothing happens, no popup, no data retrieval...

var connectionstring="DSN=Pasha;User ID=XXXXX;Password=XXXXX;

Re: Off Beat Question - Javascript - SQL

PostPosted: Sat May 25, 2013 6:16 am
by Antonio Linares
Do you get the same error ?

Re: Off Beat Question - Javascript - SQL

PostPosted: Sat May 25, 2013 6:43 am
by cdmmaui
Hi Antonio,

No, I tabbed through field with no pop up and no data population.

Re: Off Beat Question - Javascript - SQL

PostPosted: Sat May 25, 2013 7:24 am
by Antonio Linares
Darrell,

Do you mean that you already connected fine ?

Sorry, I don't understand exactly what you meant