asp.netsql-serversql-server-2008webmatrixwebmatrix-2

Migration of Access dataBase to SQLServer, what should I change in the code?


I have a web site that uses access database, I want to change connection to SQL Server DB, I migrate the Database with SQL Server, however I Have to change the connection code and sql requests.

here is a copy of what I have in the code (Im using WebMatrix):

pageConn.asp:

 <% Dim conn,connstr,Clkj_mdb
    Clkj_mdb="/DaTa/#Clkj_Cms#.mdb"
    connstr="DBQ="+server.mappath(""&Clkj_mdb&"")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
    on error resume next
    set conn=server.createobject("ADODB.CONNECTION")
    conn.open connstr
        if err then
            err.clear
            set conn=nothing
            response.write "Connect Error!"
            response.End         
        End IF
   %>

Should I change something in this part too??

Class.asp:

<% If request.querystring("Edit")="B_E" Then 
    Set Rs=server.createobject("ADODB.Recordset")
    Sql="select * from clkj_BigClass where clkj_BigClassID ="&request("clkj_BigClassID")
    Rs.open Sql,conn,1,1
%>

Thank you for your Time!


Solution

  • You don't need to make any changes to the SQL in this case, but you need to change the connection string. You can find example connection strings here: http://connectionstrings.com/sql-server-2012

    Soemthing like this should do it:

    connstr = "Provider=sqloledb;Data Source=<name of server>;Initial Catalog=<name of database>;User Id=<user id>;Password=<password>"
    

    Going forward, the main differences between JET SQL (Access) and T-SQL (SQL Server) are:

    You cannot use * in DELETE statements in T-SQL: DELETE * From MyTable becomes DELETE FROM MyTable in SQL Server.

    Yes/No columns in Access become BIT fields in SQL Server. True is represented by 1 in SQL Server, not -1 as in Access.

    If you are using # as delimiters for dates in JET SQL, you have to change them to single quotes ' in T-SQL.