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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khalid galal
    New Member
    • Apr 2008
    • 16

    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=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz;Us er ID=factory1;Pas sword = 123;";

    var ConnectObj = Server.CreateOb ject("ADODB.Con nection");
    var RS = Server.CreateOb ject("ADODB.Rec ordset");
    var sql="select * from [Quiz.mdf].dbo.Question";

    ConnectObj.Open (myConnect);
    RS.Open(sql,Con nectObj,adOpenF orwardOnly,adLo ckReadOnly,adCm dText);

    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.Ope n(myConnect);"
    Any body can give me a help?
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    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.

    Comment

    • jeffstl
      Recognized Expert Contributor
      • Feb 2008
      • 432

      #3
      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

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        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

        Comment

        • khalid galal
          New Member
          • Apr 2008
          • 16

          #5
          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.Cre ateObject("ADOD B.Connection")
          Dim myVBconnect = "Provider=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz;Us er ID=factory1;Pas sword = 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=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz.md f;User ID=factory1;Pas sword = 123;"

          Comment

          • khalid galal
            New Member
            • Apr 2008
            • 16

            #6
            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.Cre ateObject("ADOD B.Connection")
            Dim myVBconnect = "Provider=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz;Us er ID=factory1;Pas sword = 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=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz.md f;User ID=factory1;Pas sword = 123;"

            Comment

            • jeffstl
              Recognized Expert Contributor
              • Feb 2008
              • 432

              #7
              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....connect ion 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.

              Comment

              • jhardman
                Recognized Expert Specialist
                • Jan 2007
                • 3405

                #8
                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:[code=asp]<%
                set conn=Server.Cre ateObject("ADOD B.Connection")
                Dim myVBconnect
                myVBconnect = "Provider=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz;Us er ID=factory1;Pas sword = 123;"
                conn.Open myVBconnect
                %>[/code]Jared

                Comment

                • khalid galal
                  New Member
                  • Apr 2008
                  • 16

                  #9
                  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.

                  Comment

                  • khalid galal
                    New Member
                    • Apr 2008
                    • 16

                    #10
                    Thanks jhardman, i found where was he problem in my code

                    <%
                    set conn=Server.Cre ateObject("ADOD B.Connection")
                    Dim myVBconnect
                    myVBconnect = "Provider=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz;Us er ID=factory1;Pas sword = 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.Cre ateObject("ADOD B.Connection")
                    Dim myVBconnect
                    myVBconnect = "Provider=SQLNC LI;Data Source=.\SQLEXP RESS;Initial Catalog=quiz.md f;User ID=factory1;Pas sword = 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.

                    Comment

                    • jeffstl
                      Recognized Expert Contributor
                      • Feb 2008
                      • 432

                      #11
                      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.

                      Comment

                      Working...