+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 28

Thread: mdb to SQL SERVER

  1. #11
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    1,037
    Blog Entries
    2
    Rep Power
    13

    Hee hee..so it is. Didn't read back past mehere's post becasue in post #5 it appears that you are creating a connection object and then attempting to open it without setting the connection string, or anything else.
    Wolffy
    ------------------------
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.

  2. #12
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    since the connection string is in an include and you're already setting the object ... you just need to do the following:
    Code:
    'This line is not needed - Set cn = Server.CreateObject("ADODB.Connection")
     
     Set rs = Server.CreateObject("ADODB.Recordset")
     
     'This is not needed ... cn.Open conn
     
     sql = "SELECT [password] FROM [member] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    
     rs.Open sql, conn, 1
    
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  3. #13
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    In my opinion, you should'nt open the connection object in the include file, as that would open the connection as soon the include page is called.
    It should be opened in the page calling the connection object.

    I would do it like this
    Code:
    <!--#include file="adovbs.inc"-->
    
    <%
    Response.Expires = -1500
    Response.Buffer = true
    Server.ScriptTimeout = 100
    Session.Timeout = 90
    
    'Create an ADO connection object
    set conn=Server.CreateObject("ADODB.Connection")
    strSQLServerName = "XXXXXXX" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server)
    strSQLDBUserName = "SA" 'Holds the user name (for SQL Server Authentication)
    strSQLDBPassword = "test" 'Holds the password (for SQL Server Authentication)
    strSQLDBName = "db2SQL" 
    			
    'Initilise the DB Connection String
    conn.ConnectionString = "provider=SQLOLEDB; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"	
    %>
    
    And then on pages where you need the connection
    Code:
    Set rs = Server.CreateObject("ADODB.Recordset")
     
    conn.Open
     
    sql = "SELECT [password] FROM [member] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    rs.Open sql, conn, 1
    
    Also i think that you should include the file adovbs.inc on each page rather than the connection page.

  4. #14
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    1,037
    Blog Entries
    2
    Rep Power
    13

    I agree with micky here. It's kinda considered bad manners to open a connection and hold it without using it right away. There are limited connections available (as we have seen on this board of late ) to Sql Server, so the general rule is "open late, close early".
    Wolffy
    ------------------------
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.

  5. #15
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by micky View Post
    In my opinion, you should'nt open the connection object in the include file, as that would open the connection as soon the include page is called.
    It should be opened in the page calling the connection object.

    I would do it like this
    Code:
    <!--#include file="adovbs.inc"-->
    
    <%
    Response.Expires = -1500
    Response.Buffer = true
    Server.ScriptTimeout = 100
    Session.Timeout = 90
    
    'Create an ADO connection object
    set conn=Server.CreateObject("ADODB.Connection")
    strSQLServerName = "XXXXXXX" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server)
    strSQLDBUserName = "SA" 'Holds the user name (for SQL Server Authentication)
    strSQLDBPassword = "test" 'Holds the password (for SQL Server Authentication)
    strSQLDBName = "db2SQL" 
    			
    'Initilise the DB Connection String
    conn.ConnectionString = "provider=SQLOLEDB; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"	
    %>
    
    And then on pages where you need the connection
    Code:
    Set rs = Server.CreateObject("ADODB.Recordset")
     
    conn.Open
     
    sql = "SELECT [password] FROM [member] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    rs.Open sql, conn, 1
    
    Also i think that you should include the file adovbs.inc on each page rather than the connection page.
    getting this error message:

    Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    /changep3.asp, line 43


    line 43 :
    Code:
     conn.Open
    

  6. #16
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    Show your code please

  7. #17
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by micky View Post
    Show your code please
    Code:
    <!--#include file="adovbs.inc"-->
    
    <%
    Response.Expires = -1500
    Response.Buffer = true
    Server.ScriptTimeout = 100
    Session.Timeout = 90
    
    
    			'Create an ADO connection object
    			set conn=Server.CreateObject("ADODB.Connection")
    			strSQLServerName = "xxxxxxxxxx" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server)
    			strSQLDBUserName = "SA" 'Holds the user name (for SQL Server Authentication)
    			strSQLDBPassword = "test" 'Holds the password (for SQL Server Authentication)
    			strSQLDBName = "db2SQL" 
    			
    			'Initilise the DB Connection String
    			conn.connectionstring = "provider=SQLOLEDB; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"
    			
    %> 
    
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    </head>
    
    <%
    Dim submit1, oldpassword, newpassword, confirmpassword
    submit1 = Server.HTMLEncode(Request.Form("submit1"))
    oldpassword = Request.Form("oldpassword")
    newpassword = Request.Form("newpassword")
    confirmpassword = Request.Form("confirmpassword")
    'If submit1 = "confirmpassword" Then
     Dim sc, conn, rs, sql
     
    sc = conn
     
     Set conn = Server.CreateObject("ADODB.Connection")
     
     Set rs = Server.CreateObject("ADODB.Recordset")
     
     conn.Open conn
     
     sql = "SELECT [password] FROM [mem] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    
     rs.Open sql, sc, conn, 1
     
     If oldpassword = "" Or newpassword = "" Then
      Response.Write "Make sure password is valid and fill all the fields please!"
     ElseIf rs("password") <> oldpassword Then
      Response.Write "Wrong password inserted!"
     ElseIf newpassword <> confirmpassword Then
      Response.Write "Confirm password and new password are not the same!"
     ElseIf oldpassword = newpassword Then
      Response.Write "Old password and new password are the same!"
     Else
        
        sql = "UPDATE mem SET password = '" & newpassword & "' WHERE " _
      & "username = '" & Request.Form("username") & "'"
    
      conn.Execute(sql)
      Response.Write "Your Password has been changed!"
     End If
     rs.Close
     Set rs = Nothing
     conn.Close
     conn.close
     Set conn = Nothing
    'End If
    %>
    
    
    </body>
    </html>
    
    <BR><A
      HREF="#"
      ONCLICK='
       self.close();
      '
    >
     Click here to close the page
    </A></BR>
    

  8. #18
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    You dont seem to get whats being suggested here.
    You have already set the connection object once, so why do it again and why assign it to another variable sc??
    Keep this in one file like connection.asp
    Code:
    <%
    Response.Expires = -1500
    Response.Buffer = true
    Server.ScriptTimeout = 100
    Session.Timeout = 90
    
    
    'Create an ADO connection object
    set conn=Server.CreateObject("ADODB.Connection")
    strSQLServerName = "xxxxxxxxxx" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server)
    strSQLDBUserName = "SA" 'Holds the user name (for SQL Server Authentication)
    strSQLDBPassword = "test" 'Holds the password (for SQL Server Authentication)
    strSQLDBName = "db2SQL" 
    			
    'Initilise the DB Connection String
    conn.connectionstring = "provider=SQLOLEDB; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"%>
    
    Then on other page.
    Code:
    <!--#include file="adovbs.inc"-->
    <!--#include file="connection.asp"-->
    
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    </head>
    
    <%
    Dim submit1, oldpassword, newpassword, confirmpassword
    submit1 = Server.HTMLEncode(Request.Form("submit1"))
    oldpassword = Request.Form("oldpassword")
    newpassword = Request.Form("newpassword")
    confirmpassword = Request.Form("confirmpassword")
    'If submit1 = "confirmpassword" Then
    Dim rs, sql
    
    conn.open
    Set rs = Server.CreateObject("ADODB.Recordset")
     
    sql = "SELECT [password] FROM [mem] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    
     rs.Open sql, conn, 1
     
     If oldpassword = "" Or newpassword = "" Then
      Response.Write "Make sure password is valid and fill all the fields please!"
     ElseIf rs("password") <> oldpassword Then
      Response.Write "Wrong password inserted!"
     ElseIf newpassword <> confirmpassword Then
      Response.Write "Confirm password and new password are not the same!"
     ElseIf oldpassword = newpassword Then
      Response.Write "Old password and new password are the same!"
     Else
        
        sql = "UPDATE mem SET password = '" & newpassword & "' WHERE " _
      & "username = '" & Request.Form("username") & "'"
    
      conn.Execute(sql)
      Response.Write "Your Password has been changed!"
     End If
     rs.Close
     Set rs = Nothing
     conn.Close
     Set conn = Nothing
    'End If
    %>
    
    
    </body>
    </html>
    
    <BR><A
      HREF="#"
      ONCLICK='
       self.close();
      '
    >
     Click here to close the page
    </A></BR>
    

  9. #19
    Barn Enthusiast Centurion is on a distinguished road Centurion's Avatar
    Join Date
    Dec 2008
    Posts
    429
    Rep Power
    2

    Quote Originally Posted by micky View Post
    You dont seem to get whats being suggested here.
    You have already set the connection object once, so why do it again and why assign it to another variable sc??
    Keep this in one file like connection.asp
    Code:
    <%
    Response.Expires = -1500
    Response.Buffer = true
    Server.ScriptTimeout = 100
    Session.Timeout = 90
    
    
    'Create an ADO connection object
    set conn=Server.CreateObject("ADODB.Connection")
    strSQLServerName = "xxxxxxxxxx" 'Holds the name of the SQL Server (This is the name/location or IP address of the SQL Server)
    strSQLDBUserName = "SA" 'Holds the user name (for SQL Server Authentication)
    strSQLDBPassword = "test" 'Holds the password (for SQL Server Authentication)
    strSQLDBName = "db2SQL" 
    			
    'Initilise the DB Connection String
    conn.connectionstring = "provider=SQLOLEDB; Server=" & strSQLServerName & ";User ID=" & strSQLDBUserName & ";Password=" & strSQLDBPassword & ";Database=" & strSQLDBName & ";"%>
    
    Then on other page.
    Code:
    <!--#include file="adovbs.inc"-->
    <!--#include file="connection.asp"-->
    
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    </head>
    
    <%
    Dim submit1, oldpassword, newpassword, confirmpassword
    submit1 = Server.HTMLEncode(Request.Form("submit1"))
    oldpassword = Request.Form("oldpassword")
    newpassword = Request.Form("newpassword")
    confirmpassword = Request.Form("confirmpassword")
    'If submit1 = "confirmpassword" Then
    Dim rs, sql
    
    conn.open
    Set rs = Server.CreateObject("ADODB.Recordset")
     
    sql = "SELECT [password] FROM [mem] " _
      & "WHERE [username] = '" & Request.Form("username") & "'"
    
    
     rs.Open sql, conn, 1
     
     If oldpassword = "" Or newpassword = "" Then
      Response.Write "Make sure password is valid and fill all the fields please!"
     ElseIf rs("password") <> oldpassword Then
      Response.Write "Wrong password inserted!"
     ElseIf newpassword <> confirmpassword Then
      Response.Write "Confirm password and new password are not the same!"
     ElseIf oldpassword = newpassword Then
      Response.Write "Old password and new password are the same!"
     Else
        
        sql = "UPDATE mem SET password = '" & newpassword & "' WHERE " _
      & "username = '" & Request.Form("username") & "'"
    
      conn.Execute(sql)
      Response.Write "Your Password has been changed!"
     End If
     rs.Close
     Set rs = Nothing
     conn.Close
     Set conn = Nothing
    'End If
    %>
    
    
    </body>
    </html>
    
    <BR><A
      HREF="#"
      ONCLICK='
       self.close();
      '
    >
     Click here to close the page
    </A></BR>
    
    Hi Micky,

    getting this error?

    error '80020009'

    line 28, :
    Code:
     ElseIf rs("password") <> oldpassword Then
    
    mera website kaam nahi kar raha hei

  10. #20
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    683
    Blog Entries
    1
    Rep Power
    6

    koi baat nahi, chalne lagegi, chinta mat kar

    You need to check if your recordset has a record or not, before you can read its value like rs("password").
    So add such code
    Code:
    If NOT rs.BOF and NOT rs.EOF
     If oldpassword = "" Or newpassword = "" Then
      Response.Write "Make sure password is valid and fill all the fields please!"
     ElseIf rs("password") <> oldpassword Then
      Response.Write "Wrong password inserted!"
     ElseIf newpassword <> confirmpassword Then
      Response.Write "Confirm password and new password are not the same!"
     ElseIf oldpassword = newpassword Then
      Response.Write "Old password and new password are the same!"
     Else
        
        sql = "UPDATE mem SET password = '" & newpassword & "' WHERE " _
      & "username = '" & Request.Form("username") & "'"
    
      conn.Execute(sql)
      Response.Write "Your Password has been changed!"
     End If
     End If
    rs.Close
     Set rs = Nothing
     conn.Close
     Set conn = Nothing
    'End If
    

+ Reply to Thread
Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. SQL Server Integration Services
    By guddu in forum Microsoft SQL Server
    Replies: 1
    Last Post: April 24th, 2009, 07:08 AM
  2. SQL Server CREATE TABLE..LIKE
    By Wolffy in forum SQL Code Samples
    Replies: 2
    Last Post: March 12th, 2009, 04:51 PM
  3. SQL Server 2008
    By stephenhy88 in forum Microsoft SQL Server
    Replies: 7
    Last Post: August 13th, 2008, 01:55 AM
  4. SQL Server Views
    By theChris in forum Microsoft SQL Server
    Replies: 3
    Last Post: March 23rd, 2008, 07:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO