468,168 Members | 1,509 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,168 developers. It's quick & easy.

Having a problem with connecting ASP with MSSQL SEVER 2005 EXPRESS EDITION

Hi, i am having a problem with connecting ASP with MSSQL SEVER 2005 EXPRESS EDITION, i am writing ASP code using javascript.
look at this peace of code:

var myConnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz;User ID=factory1;Password = 123;";

var ConnectObj = Server.CreateObject("ADODB.Connection");
var RS = Server.CreateObject("ADODB.Recordset");
var sql="select * from [Quiz.mdf].dbo.Question";

ConnectObj.Open(myConnect);
RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockRea dOnly,adCmdText);

The IIS throws an error says:

"Microsoft SQL Native Client (0x80004005)
Named Pipes Provider: Could not open a connection to SQL Server [53]. "

at "ConnectObj.Open(myConnect);"
Any body can give me a help?
Aug 6 '08 #1
10 3771
jeffstl
432 Expert 256MB
Javascript is not built to connect to databases.

Javascript runs locally on the users machine. So your not going to be able to connect to a server side database.

If you want to write ASP pages that connect to a SQL database you need to write server side ASP\vbscript, or use coldfusion or some other server side scripting.

You can use JAVA to connect to databases but these would be .jsp server side files as well. Also thats totally different from javascript which is usually strictly used for event handling on the client side.
Aug 6 '08 #2
jeffstl
432 Expert 256MB
Technically actually there are "tricks" you can do to use javascript to CALL server side scripts to execute database connections.

But the way you are trying to implement the code aboave is not correct. The code you have above is closer to vbscript then javascript.

Anyway here is an interesting trick in using JDBC trick to use javascript for database connectivity locally. I would probably NOT recommend trying this though if you are unfamiliar with web programming methods

Javascript servlet trick
Aug 6 '08 #3
jhardman
3,405 Expert 2GB
actually looks like he's writing in JSP which is the same as ASP, but with jscript as the language rather than vbscript. If that's the case, then yes you can connect with javascript.

That aside, I don't see what's wrong. I'm not a jscript guru (I don't think many people are) but I think your db connection is the problem, regardless. db connections can be a real headache. I always use a dsn to connect, it takes more work to set up, but then it goes smoother. If you have any questions about setting up a DSN or connecting to it, I would be happy to help you out.

Jared
Aug 8 '08 #4
Thanks jeffstl and jhardman i want to give this reply to jeffstl.
I made as suggestion and i tried it the same code with vbscript, the code is:

<%
set conn=Server.CreateObject("ADODB.Connection")
Dim myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz;User ID=factory1;Password = 123;";
conn.Open myVBconnect
%>

And i get this error message

Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/MyWeb/yaRab2.asp, line 3, column 16
Dim myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz.mdf;User ID=factory1;Password = 123;"
Aug 8 '08 #5
Thanks jeffstl and jhardman, i want to give this reply to jeffstl.
I made as your suggestion and i tried the same code with vbscript, the code is:

<%
set conn=Server.CreateObject("ADODB.Connection")
Dim myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz;User ID=factory1;Password = 123;"
conn.Open myVBconnect
%>

And i get this error message

Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/MyWeb/yaRab2.asp, line 3, column 16
Dim myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz.mdf;User ID=factory1;Password = 123;"
Aug 8 '08 #6
jeffstl
432 Expert 256MB
Sorry I did not explain what I meant fully. IIS alone cannot run JSP. You need a java server to do that. Like Apache or Tomcat.

Another note, things like ADODB, and RS.Open are strictly Microsoft controls that compile and run on IIS. (vbscript controls, javascript will have no idea what they are).

Java and javascript are two completely different things and to my knowledge you cannot use javascript to connect to a database.

You can use Java (Java Server Pages, Java Beans, etc) which are .jsp's which again by default can only deploy on a Apache or Tomcat server.

All that being said, your code all looks to me like vbscript, ASP code. And the errors are IIS errors. So the bottom line is you are not coding in javascript here, you are using vbscript. At first glance all I can suggest is to modify your connection string. It seems to me a path or provider problem.

As Jhardman said....connection strings are rough sometimes because they are very dependant on local settings, paths, types of databases, etc. I suggest either trying a connection string you know for certain will work first, and see if you are missing a provider reference, or a different version of a provider or if the path needs to be modified.
Aug 8 '08 #7
jhardman
3,405 Expert 2GB
Java and javascript are two completely different things and to my knowledge you cannot use javascript to connect to a database.

You can use Java (Java Server Pages, Java Beans, etc) which are .jsp's which again by default can only deploy on a Apache or Tomcat server.
Sorry, Jeff. jsp's can run on IIS alone, but they need to be written in microsoft's implementation of javascript, which is actually called "jscript". This does work on IIS exactly like vbscript. This is why some coders specify which language they use in their asp pages.

that said, khalid, your vbscript syntax is incorrect. try this:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. set conn=Server.CreateObject("ADODB.Connection")
  3. Dim myVBconnect
  4. myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz;User ID=factory1;Password = 123;"
  5. conn.Open myVBconnect 
  6. %>
Jared
Aug 8 '08 #8
Thanks jeffstl and jhardman, i want to give this reply to jeffstl.
I made as your suggestion and i got this error message from the IIS:

Error Type:
Microsoft SQL Native Client (0x80004005)
Cannot open database "quiz" requested by the login. The login failed.

I think its a permission problem, by the way i changed my server authentication mode to SQL Server and Windows authntication mode in MS SQL SERVER MANAGEMENT STUDIO EXPRESS 2005 and i made my user id "factory1" and my password "123" and i allowed remote connections from the SQL SERVER SURFACE AREA CONFIGURATION.

I also made a remote connection from NetBeans (Java programming language) to the same database, user id, and password, and it worked perfectly.

Thanks.
Aug 9 '08 #9
Thanks jhardman, i found where was he problem in my code

<%
set conn=Server.CreateObject("ADODB.Connection")
Dim myVBconnect
myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz;User ID=factory1;Password = 123;"
conn.Open myVBconnect
%>

when i changed the Initial Catalog from "quiz" to "quiz.mdf" it worked, so this is the code:

<%
set conn=Server.CreateObject("ADODB.Connection")
Dim myVBconnect
myVBconnect = "Provider=SQLNCLI;Data Source=.\SQLEXPRESS;Initial Catalog=quiz.mdf;User ID=factory1;Password = 123;"
conn.Open myVBconnect
%>

Another thing i'd like to thank jeffstl and i'd like to tell him that his suggestion is right so when i try the same code above which is the one who worked in javascript an error message is thrown from the IIS and says:

Microsoft SQL Native Client (0x80004005)
Named Pipes Provider: Could not open a connection to SQL Server [53].

That's probably because i am using ASP/javascript because the same code in vbscript works.

Thanks to ALLAH first then to jeffstl and jhardman for their help.
Aug 9 '08 #10
jeffstl
432 Expert 256MB
Sorry, Jeff. jsp's can run on IIS alone, but they need to be written in microsoft's implementation of javascript, which is actually called "jscript". This does work on IIS exactly like vbscript. This is why some coders specify which language they use in their asp pages.
OK. Hm

I don't doubt you. That is interesting. I just always thought that javascript was strictly for event handling and local execution and some very primitive DHTML type of uses.

I never knew it could be used for a full fledged application like that with database connectivity, etc unless you were actually using JAVA.
Aug 12 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by mj | last post: by
2 posts views Thread by =?Utf-8?B?QWlya29u?= | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.