Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Newbie
 
Join Date: Apr 2008
Posts: 16
#1: Aug 6 '08
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?

jeffstl's Avatar
Expert
 
Join Date: Feb 2008
Posts: 414
#2: Aug 6 '08

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


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.
jeffstl's Avatar
Expert
 
Join Date: Feb 2008
Posts: 414
#3: Aug 6 '08

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


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
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#4: Aug 8 '08

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


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
Newbie
 
Join Date: Apr 2008
Posts: 16
#5: Aug 8 '08

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


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;"
Newbie
 
Join Date: Apr 2008
Posts: 16
#6: Aug 8 '08

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


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;"
jeffstl's Avatar
Expert
 
Join Date: Feb 2008
Posts: 414
#7: Aug 8 '08

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


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.
jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#8: Aug 8 '08

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


Quote:

Originally Posted by jeffstl

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
Newbie
 
Join Date: Apr 2008
Posts: 16
#9: Aug 9 '08

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


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.
Newbie
 
Join Date: Apr 2008
Posts: 16
#10: Aug 9 '08

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


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.
jeffstl's Avatar
Expert
 
Join Date: Feb 2008
Posts: 414
#11: Aug 12 '08

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


Quote:

Originally Posted by jhardman

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.
Reply