Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 181
  • Last Modified:

Change JET Database connection to SQL Server Connection

Hello All;

Here is the JET Connection
		
Private Function GetConnectionString() As String
Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(MDBFILE) & ";"
End Function

Open in new window


This is my SQL Server Connection

Dim cn As System.Data.SqlClient.SqlConnection
cn = New System.Data.SqlClient.SqlConnection("Data Source=SERVER\2005;Database=cs;User ID=username;Password=******;")
cn.Open()

Open in new window


The original code can be found at the top of the page here
http://www.experts-exchange.com/Q_27024841.html

Thanks
Carrzkiss
0
Wayne Barron
Asked:
Wayne Barron
  • 2
1 Solution
 
CodeCruiserCommented:
Not sure what the question is.

One thing is that with Jet, you use OLEDB provider where as with Sql Server, you would use the SQLClient provider which is in System.Data namespace.
0
 
Wayne BarronAuthor Commented:
Here is the code that I went with.
I took it from another project, and ripped out all the insert/update code that was originally in this project, and made it work with my own.

<%
Dim objConnection As OleDbConnection = Nothing
Dim objCmd As OleDbCommand = Nothing
Dim strConnection As [String], strSQL As [String]
Dim cn As System.Data.SqlClient.SqlConnection
strConnection = "Provider=SQLOLEDB;Data Source=2005;Database=cs;User ID=username;Password=********;"
cn.Open()

        
                objConnection = New OleDbConnection(strConnection)
                objConnection.ConnectionString = strConnection
        
                objConnection.Open()
                strSQL = "INSERT INTO csFiles(Filename, FileSize, csid)VALUES(?,?,1)"
                objCmd = New OleDbCommand(strSQL, objConnection)
                objCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Filename", strName))
                objCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@FileSize", Buffer.Length))
                'objCmd.Parameters.Add(New System.Data.OleDb.OleDbParameter("@csid", 1)
                objCmd.ExecuteNonQuery()
%>

Open in new window



Thanks codecruiser for taking a look.
This is completed.

Carrzkiss
0
 
Wayne BarronAuthor Commented:
Remembered code that I had used before, and implemented it into the project.
Works like a charm.
Code Supplied.

Carrzkiss
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now