|
-
June 22nd, 2010, 02:58 PM
#1
Change ASP Connection String Access to SQL
Changing a connection string on Web Site.
They were using an Access connection to connect, and I want to substitute the SQL Server connection string. Just wanted to make sure I do it right.
This is the Acces Connection that I have:
Code:
Dim cn
Set cn=server.createobject("adodb.connection")
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\") & "\data\kallenrs.mdb;"
cn.open
This is the SQL Connection that I want for LOCAL testing, and I can change that later:
Code:
Driver={SQL Server Native Client 10.0};Server=.\SQLEXPRESS; Database=tracking2010;Trusted_Connection=yes;
I'll use "Select fID as FileNumber, x as a, y as b, z as c" to keep the naming convention the same.
Thanks!
-
June 22nd, 2010, 03:17 PM
#2
Re: Change ASP Connection String Access to SQL
Something like this?
Code:
Dim cn
Set cn=server.createobject("adodb.connection")
cn.ConnectionString = "Driver={SQL Server Native Client 10.0};Server=.\SQLEXPRESS; Database=tracking2010;Trusted_Connection=yes;"
-
June 23rd, 2010, 05:55 AM
#3
Re: Change ASP Connection String Access to SQL
Hi David 
Why don't you make use of the SQL connection objects? Any specific reason?
You could Add the Namspace :
Code:
Imports System.Data.SqlClient
Then :
Code:
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim ds As DataSet
Dim da As SqlDataAdapter
con = new SqlConnection("Server=You server name or compname; Database=Yourdatabasename;Trusted_Connection=True")
cmd = new SqlCommand("Write your sql query here eg. select * from Table name")
con.Open();
ds = new DataSet(cmd,con)
da = new SqlDataAdapter()
da.Fill(ds)
con.Close()
Does this help ?
-
June 23rd, 2010, 12:35 PM
#4
Re: Change ASP Connection String Access to SQL
Nope. Legacy DB, and the app runs on it.
I have that already. I need to modify it to open an MDB file using ADODB or OLEDB, if it's possible.
Besides this code is running in an ASP page, using VBA
-
June 23rd, 2010, 01:35 PM
#5
Re: Change ASP Connection String Access to SQL
I am using some more like this if memory serves
"Provider=MSDASQL; DRIVER=Sql Server; SERVER=x24400; DATABASE=MyDatabase; UID=sa; PWD=PW"
I'll look and see if I can find the web code I have where I used SQL server
Always use [code][/code] tags when posting code.
-
June 23rd, 2010, 01:46 PM
#6
Re: Change ASP Connection String Access to SQL
hmm.. I must have archived the old web code no longer on my system I can't be sure now but I think that is the way I did it. Worked with SQL server 2000 don't know about express
Always use [code][/code] tags when posting code.
-
June 23rd, 2010, 02:37 PM
#7
Re: Change ASP Connection String Access to SQL
Same thing. Never displays anything. Must not be connecting.
Code:
Dim cn
Set cn=server.createobject("adodb.connection")
' Set cn=server.createobject("MSDASQL.connection")
' cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("\") & "\data\kallenrs.mdb;"
' cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\kallenrs\data\kallenrs.mdb;"
cn.ConnectionString = "Provider=MSDASQL;DRIVER=Sql Server;Server=whs-siok\SQLSERVER;Database='Tracking2010';Integrated Security = SSPI;"
'
' cn.ConnectionString = "Provider=SQLOLEDB;Data Source=whs-siok\SQLSERVER;Initial Catalog='Tracking2010';Integrated Security = SSPI;"
' cn.ConnectionString = "Driver={SQL Native Client};Server=whs-siok\SQLEXPRESS;Database=Tracking2010;Trusted_Connection=yes;"
response.write(cn.ConnectionString)
' <add name="ConnectionString" connectionString="Integrated Security=SSPI;Pooling=false;Data Source=.\SQLEXPRESS;Initial Catalog=tracking2010"/>
' <add name="ConnectionString" connectionString="Data Source=rs.db.*****.*****.com;Initial Catalog=kallenrs;User Id=sa;Password=pw;" />
cn.open
If Err.Number > 0 Then
Response.Redirect "Error.htm"
End If
break
Being redirected to ERROR.HTM
-
June 24th, 2010, 03:44 AM
#8
Re: Change ASP Connection String Access to SQL
-
June 24th, 2010, 12:24 PM
#9
Re: Change ASP Connection String Access to SQL
It opens the Jet db but not the SQL db.
-
June 24th, 2010, 02:41 PM
#10
Re: Change ASP Connection String Access to SQL
Always use [code][/code] tags when posting code.
-
June 24th, 2010, 07:30 PM
#11
Re: Change ASP Connection String Access to SQL
Thanks, tried them all, but none seem to be working. Not sure how to debug this. I guess I need to find someone that has already done this. It might help others.
-
July 2nd, 2010, 07:56 AM
#12
Re: Change ASP Connection String Access to SQL
SUCCESS!
Code:
<%
Dim dbhost, dbname_and_username, dbpwd, oConn, dbConn
dbhost = "x.x.x"
dbname_and_username = "xxx"
dbpwd = "yyy"
dbase1 ="zzz"
Set oConn = Server.CreateObject("ADODB.Connection")
dbConn = "DRIVER=SQL Server; SERVER="& dbhost &"; UID="& dbname_and_username &"; database="& dbase1 &";PWD="& dbpwd &"; Network Library=dbmssocn;"
oConn.Open(dbConn)
Set oConn = Server.CreateObject("ADODB.Connection")
dbConn = "DRIVER=SQL Server; SERVER="& dbhost &"; UID="& dbname_and_username &"; database="& dbase1 &";PWD="& dbpwd &"; Network Library=dbmssocn;"
oConn.Open(dbConn)
Dim dateRS, dateSQL
Set dateRS = Server.CreateObject("ADODB.Recordset")
dateSQL = "SELECT [fSaleDate], [fCaseNumber], [fAddress], [fJudgmentAmount], " & _
"[fSaleResult] FROM [********] ORDER BY [fSaleDate]"
Set dateRS = oConn.Execute(dateSQL)
While Not dateRS.EOF
response.write("* " & dateRs("fSaleDate") & " * " & dateRs("fCaseNumber") & " * " & dateRs("fAddress") & _
" * " & dateRs("fJudgmentAmount") &" * " & dateRs("fSaleResult") & " * <BR>")
response.write("* ------------------------------------------------------------------------------" & _
"--------------------------------------------------------------- " & " * <BR>")
dateRS.MoveNext
Wend
Set dateRS = Nothing
oConn.Close
Set oConn = Nothing
If Err.Number > 0 Then
Response.Redirect "Error.htm"
' Else
' response.write "Success"
End If
%>
-
July 2nd, 2010, 08:01 AM
#13
Re: Change ASP Connection String Access to SQL
Did it require the connection to be entered twice or is this just left over from testing?
Code:
Set oConn = Server.CreateObject("ADODB.Connection")
dbConn = "DRIVER=SQL Server; SERVER="& dbhost &"; UID="& dbname_and_username &"; database="& dbase1 &";PWD="& dbpwd &"; Network Library=dbmssocn;"
oConn.Open(dbConn)
Set oConn = Server.CreateObject("ADODB.Connection")
dbConn = "DRIVER=SQL Server; SERVER="& dbhost &"; UID="& dbname_and_username &"; database="& dbase1 &";PWD="& dbpwd &"; Network Library=dbmssocn;"
oConn.Open(dbConn)
Always use [code][/code] tags when posting code.
-
July 2nd, 2010, 08:02 AM
#14
Re: Change ASP Connection String Access to SQL
Glad you got it fixed! Sorry I wasn't much help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|