Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript and connection strings

Status
Not open for further replies.

zerkat

Programmer
Jul 12, 2007
103
US

I wrote a stored procedure to replace the functionality in this one application at work. The application is ASP with javasript. Is it possible to call a stored procedure using javascript? If so, could someone please provide an example of how to do this? I searched on the web and didn't find much using javascript.

Thanks.
 
oh, I am using sql 2005....forgot to add that to my post :)
 
The only way that I know how to do that is to do an XHR call to a Java Adapter that will call the procedure through JDBC.

Doubt that helps, but maybe a start?
 
uhm, I am not using JDBC though - database is SQL. Maybe I am not understanding what you are getting at?

I just saw in one of my reference books that javascript does have a connection object for databases. Will do some more research into this...
 
You should be able to call a SQL server stored proc using JavaScript ASP. This code is about 7 years old now, but I'm sure the principal hasn't changed that much:

Code:
var cn = Server.CreateObject("ADODB.Connection");
cn.ConnectionString = "driver={SQL Server};server=<hostname>;uid=<username>;pwd=<password>;database=<dbname>;";
cn.Open();

var rs = Server.CreateObject("ADODB.Recordset");
var SQLstr = "storedProcName <params here>";
rs.Open(SQLstr, cn);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks dan - that pointed me in the right direction...

i have some variables set up that store form values that i want to use as params so to do that I just need to place the variable names with the storedProcName like this?

var x = form.textfield.value
var SQLstr = "storedProcName x";

How would I differentiate input and output variables? I am used to seeing this in vbscript so am a little confused...
 
I think you're confusing client-side and server-side JavaScript here. Your form variables would need to be sent server-side, and picked up there.

Well, at least, the code I gave was designed to be run server-side. Maybe it will work client-side? It's been a while since I've done any DB access with JS.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top