Groups | Blog | Home
all groups > dotnet jscript > april 2005 >

dotnet jscript : Use JavaScript or Jscript to connect SQL2000, posible?


WTS
4/20/2005 2:18:02 AM
Hit there,

I am searching hi and lo for the above mentioned. Is it posible to do? If
so, how?
I want to use this script at my aspx page.

Thanks in advance.

Bruce Barker
4/20/2005 9:08:19 AM
yes.

1) with javascript, use the ado com classes
2) with jscript.net use SqlClient classes

-- bruce (sqlwork.com)


[quoted text, click to view]

WTS
4/21/2005 7:13:08 AM
Thanks for your tip, Bruce.

Is there any sample code for JScript to connect SQL?

Regards

WTS


[quoted text, click to view]
Serge Baltic
4/21/2005 8:03:06 AM
W> Is there any sample code for JScript to connect SQL?

Both mentioned technologies (ADO and SqlClient) are language-independent
and can be used from ANY language you like in the same way. Just use any
example and change its syntax a bit to fit JScript specs. Thus no much need
for such samples.

(H) Serge

WTS
4/21/2005 7:34:02 PM
Thanks Serge,

I did try earlier to interprete it into jscript, but it return error as
"Server" is undefined".

my code example
<script language="jscript">
function try()
{
var myCon = Server.CreateObject("ADODB.Connection");
...
}
</script>


[quoted text, click to view]
Serge Baltic
4/22/2005 4:09:38 AM

W> I did try earlier to interprete it into jscript, but it return error
W> as "Server" is undefined".

W> <script language="jscript">

Seems like you're trying to write this in client-side script instead of server-side.
So it gets executed in the user's browser — and there's no server in it,
definitely.

For an aspx page, write the code either in the codebehind class, or in a
<script runat="server"> tag, or in between the <% and %> tags, to get it
executed on the server.

Also, Server.CreateObject seems to me to be come legacy of non-.NET-ASP (not
aspX), which helped it to deal with apartments and object lifetime. In JScript.NET
you could use "new ActiveXObject(…)" instead. But that's my IMHO and may
have some impact on server work. Either way, will be OK for a startup sample,
I think.

PS check the "C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\QuickStart\howto\samples"
or similar, if you've gotten Visual Studio or .NET SDK — there are samples
for what you're trying to do. Sometimes in JS too.

(H) Serge

Bruce Barker
4/22/2005 4:51:50 PM
the Server object is only supported by classic asp. what enviroment are you
using (wsh, browser, asp, asp.net?). if you are using the browser, then you
will not have permission to create the objects unless the site is trusted.

try:

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


-- bruce (sqlwork.com)






[quoted text, click to view]

WTS
4/22/2005 8:15:02 PM
Hi Bruce & Serge,

Thanks for all your tips. I finally got it and everything works beautifully!

Best reagards to you.

WTS


[quoted text, click to view]
AddThis Social Bookmark Button