I'm using MS Access as my database, my hosting is not supporting this, and I need to know how to convert MS Access to SQL Server connection string?
This my code of data connection:
'--------------- ole parameters -------------------
Dim olecommand As Data.OleDb.OleDbCommand
Dim oledataadaptor As Data.OleDb.OleDbDataAdapter
Dim odbcDataSet As System.Data.DataSet
Sub populate_dataset_Access_accdb_test(ByRef ds As DataSet, ByVal sql As String)
Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
olecommand = New OleDb.OleDbCommand
olecommand.CommandText = sql
odbcDataSet = New System.Data.DataSet
olecommand.Connection = myDataConnection
myDataConnection.Open()
oledataadaptor = New OleDbDataAdapter(sql, myDataConnection)
oledataadaptor.Fill(ds)
myDataConnection.Close()
End Sub
Sub insert_dataset_Access_accdb_test(ByVal sql As String)
Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
olecommand = New OleDb.OleDbCommand
olecommand.CommandText = sql
odbcDataSet = New System.Data.DataSet
olecommand.Connection = myDataConnection
myDataConnection.Open()
olecommand = New OleDbCommand(sql, myDataConnection)
olecommand.ExecuteNonQuery()
myDataConnection.Close()
End Sub
Sub cr_ds(ByRef ds As DataSet, ByVal sql As String, ByVal tablename As String)
Dim myDataConnection As New OleDbConnection(ConfigurationManager.ConnectionStrings("myodbc").ConnectionString)
olecommand = New OleDb.OleDbCommand
olecommand.CommandText = sql
odbcDataSet = New System.Data.DataSet
olecommand.Connection = myDataConnection
myDataConnection.Open()
oledataadaptor = New OleDbDataAdapter(sql, myDataConnection)
oledataadaptor.Fill(ds, tablename)
myDataConnection.Close()
End Sub
Thank you in advance
As Steve Wellens pointed out, you miss some basic things here. Since your host does not support your data source type (MS Access), changing your connection string is not enough. You have to use a data store supported by your hosting service. I suppose that Microsoft SQL Server is one of them, but you have to verify it by contacting your hosting service administration support.
Regarding the transfer of data between MS Access and MS SQL Server, you could get some guidance here.
Regarding the MS SQL Server connection strings, you could get some help from this post but you have to verify the availability of the MS SQL Server database with your hosting service.
Hope I helped!
You can't just change an Access connection string to an SQL connection string and have things work. You would have to port your data From Access to the SQL Server.
I think it is more likely that when you deploy your Access database to the server, the path is different. You probably need to modify the config file to point to to where the Access file is on the server.
Related
i try to fetch records from Apache Ignite inmemory database via Microsoft Access 2016 32-Bit and Apache Ignite 32-Bit ODBC-driver with default settings. OS is Windows 10.
Import as a linked table does not work so i tried via ADODB-Class.
Connection.Open and Recordset.Open works and i can see all columns (ID and NAME) of sample table CITY in the Recordset. But when i try to fetch the first record with MoveFirst or MoveNext, i get the error 'specified attribute is not supported'. I tried the same with CursorLocation=adUseClient and the error message changes to 'wrong parameter'. Default Provider is MSDASQL.1. Is this the correct Provider? Any idea how to fetch records with ADODB?
Code
`
Public Sub QueryIgnite()
Dim ADOrs As ADODB.Recordset
Dim ADOcon As ADODB.Connection
Set ADOcon = New ADODB.Connection
ADOcon.ConnectionString = "DSN=Apache-Ignite-DSN"
'ADOcon.CursorLocation = adUseClient
ADOcon.Open
Set ADOrs = New ADODB.Recordset
ADOrs.Open "select * from city", ADOcon, adOpenForwardOnly
ADOrs.MoveNext
Debug.Print ADOrs.Fields("NAME")
ADOrs.Close
ADOcon.Close
End Sub
`
Thank you in advance.
Regards.
Guido Clesius
A ticket on apache.org is created to fix the bug. See https://issues.apache.org/jira/browse/IGNITE-18210
This is the scenario:
I'm doing a web service in WCF and a client application in ASP.NET. The language is VB.NET.
I want a method than send "jobs" to the server. I'm trying to simulate this kind of jobs as long running processes that wait up to 20-30 seconds with thread sleeping and inserting a row into a JOBS table in the DB.
I want another method that polls the database every 5 seconds with client postbacks to get the jobs lists from the JOBS table (finished and currently running)
This is what i've got so far, both methods are working, except when a long running job is sleeping, then the client can't retrieve the list of jobs with another call. I've tried "PerCall" in the but it didn't work out. I suspect the thread is somewhat locking the service or maybe I have to use async calls. I'm using HttpBasicBinding at web.config ... I'm a little lost and I have not found any code doing something similar.
Here is the code in the service side:
iServiceJobs.vb
<ServiceContract()>
Public Interface IServiceJobs
<OperationContract(IsOneWay:=True)>
Sub SendJob(ByVal runTime As Integer, ByVal id As String)
<OperationContract>
Function GetJobsList() As List(Of ClassJob)
ServiceJobs.vb
Public Class ServiceJobs Implements IServiceJobs
Public SendJob(ByVal runTime As Integer, ByVal id As String) Implements IServiceJobs.SendJob
Dim connStr As String = "..."
Dim conn As New OracleConnection(connStr)
conn.Open()
Dim query As String = "INSERT INTO JOBS(...)"
Dim cmd As New OracleCommand(query, conn)
cmd.ExecuteNonQuery()
Threading.Thread.Sleep(runTime* 1000)
cmd = New OracleCommand(query, conn)
cmd.ExecuteNonQuery()
End Sub
Public Function GetJobList() As List(Of ClassJob) Implements IServiceJobs.GetJobsList
Try
Dim jobList As New List(Of ClassJobs)
Dim connStr As String = "..."
Dim conn As New OracleConnection(connStr)
conn.Open()
Dim query As String = "SELECT * FROM JOBS"
Dim cmd As New OracleCommand(query, conn)
Dim dr As OracleDataReader
Dim job As ClassJob
dr = cmd.ExecuteReader
While dr.Read
job = New ClassJob
job.id = dr(0)
job.lock = dr(3)
...
jobList.Add(job)
job = Nothing
End While
Return jobList
Catch ex As Exception
Return Nothing
End Try
End Function
End Class
The code in the client is very simple, just two buttons, one with a ws call for insert jobs and another to get the job list.
I'm open to any suggestion on how to do a better implementation of this scenario.
EDIT:
I've tried
<ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Multiple, InstanceContextMode:=InstanceContextMode.PerCall)>
But it doesn't work, GetJobList() returns Nothing while SendJob() is working on this thread.
SOLVED: Apparently, I was using an outdated version of Oracle libraries. When I used Oracle.ManagedDataAccess from NuGet everything went OK.
SOLVED: Apparently, I was using an outdated version of Oracle libraries. When I used Oracle.ManagedDataAccess from NuGet everything went OK.
I have an old web application written in ASP.Net 2.0 Web Forms. I use the Data Access Block in Enterprise Library and have recently updated to version 5.0. The application is tiered, ie, UI layer, Service Layer, Data Layer. It also uses SQL Server 2008 for the data storage.
I have recently noticed that the following error is appearing when I run the application and browse to particular pages.
Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
This tends to happen on pages that do a lot of separate reads from the database, maybe up to as many as 20 on one page.
Below shows snippets of my Data Access Class.
Public Class DataAccess
' create a private instance of the database factory
Private db As Database = DatabaseFactory.CreateDatabase()
Public Function ExecuteNonQuery(ByVal params() As SqlParameter, ByVal strSproc As String) As Integer
Dim intReturnValue As Integer = 0
Dim i As Integer
Dim cmd As DbCommand
cmd = db.GetStoredProcCommand(strSproc)
cmd.CommandTimeout = 120
For i = 0 To params.Length - 1
db.AddInParameter(cmd, params(i).ParameterName.ToString, params(i).DbType, params(i).Value)
Next
db.AddParameter(cmd, "return_value", DbType.Int32, ParameterDirection.ReturnValue, "", DataRowVersion.Default, 0)
db.ExecuteNonQuery(cmd)
intReturnValue = Int32.Parse(db.GetParameterValue(cmd, "#return_value"))
Return intReturnValue
End Function
Public Function ExecuteDataReader(ByVal params() As SqlParameter, ByVal SProc As String) As SqlDataReader
Dim i As Integer
Dim dr As SqlDataReader = Nothing
Dim cmd As DbCommand
cmd = db.GetStoredProcCommand(SProc)
cmd.CommandTimeout = 120
For i = 0 To params.Length - 1
db.AddInParameter(cmd, params(i).ParameterName.ToString, params(i).DbType, params(i).Value)
Next
dr = TryCast(DirectCast(db.ExecuteReader(cmd), RefCountingDataReader).InnerReader, SqlDataReader)
Return dr
End Function
Throughout my code, once I have finished with an SqlDataReader I always do something like this
If Not (drSource Is Nothing) Then
drSource.Close()
End If
Is there anything you folk can see that I am missing? Does it look like my code could be leaking connections or not closing properly?
I always thought the Garbage collector got rid of any open connections.
Any feedback or help would be greatly appreciated.
Thanks.
Your code is closing the data reader, but not the data connection associated with it.
Since your data reader is a SqlDataReader, it has a Connection property. You should be able to use that to close and dispose of the connection.
In my ASP.NET(3.5) project, I am using inbuilt TableAdapters/Dataset for all Data Access. Does it provide the same security as SQLDataSource does from SQL injection? I am using parameters as follows.
Dim myDAL As New ABCTableAdapters.XYZTableAdapter
Label1.Text = myDAL.getDatafromDB(myParameter)
Update 1:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim myParameter As String = getSafeURL(Request.QueryString("MS_Code")) 'getsafeurl encodes querystring using HttpUtility.UrlEncode
Dim myDAL As New ABCTableAdapters.XYZTableAdapter
Label1.Text = myDAL.getDatafromDB(myParameter)
End Sub
getDatafromDB corresponds to following query present in app_code/DAL.xsd
SELECT something FROM sometable where fieldname = #parameter
Update 2:
If I 'View Code' of XSD I am able to see following
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="true">
<CommandText>SELECT pageContent FROM [content] where name = #name</CommandText>
<Parameters>
<Parameter AllowDbNull="true" AutogeneratedName="name" ColumnName="name" DataSourceName="iseac.dbo.[content]" DataTypeServer="nchar(100)" DbType="String" Direction="Input" ParameterName="#name" Precision="0" ProviderType="NChar" Scale="0" Size="100" SourceColumn="name" SourceColumnNullMapping="false" SourceVersion="Current" />
</Parameters>
</DbCommand>
</SelectCommand>
It depends.
You could get SQL injection if you badly use tableAdapters.
The main thing is to use SqlParameters for all data that is gathered from users.
Can you show some of your data access code ?
Look up here How To: Protect From SQL Injection in ASP.NET
using System.Data;
using System.Data.SqlClient;
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet userDataset = new DataSet();
SqlDataAdapter myDataAdapter = new SqlDataAdapter(
"SELECT au_lname, au_fname FROM Authors WHERE au_id = #au_id",
connection);
myCommand.SelectCommand.Parameters.Add("#au_id", SqlDbType.VarChar, 11);
myCommand.SelectCommand.Parameters["#au_id"].Value = SSN.Text;
myDataAdapter.Fill(userDataset);
}
The important part here is that user entered data (what comes in from web request) is passed to DB inside database parameters like #au_id. In that case you are protected from SQL injection.
BAD WAY would be this (DON'T USE THIS):
myCommandText = string.Format(
"SELECT au_lname, au_fname
FROM Authors WHERE au_id = {0}", SSN.Text)
This way user can manipulate what is send to DB and if your connection to DB has enough privileges it can drop tables or database. Or it can silently modify your data and that is even worse.
So, always use database parameters.
Additionally if you do you gain in performance, because DB will cache execution plan and if you later execute same SQL with only different values for parameters, DB already have execution plan and it doesn't need to parse sql again.
Okay this question could either be very broad or very specific because I am not sure if I am going about this in a fundamentally wrong way or if I am close to correct.
First an overview: What I am trying to do it create a server application for all of the clients in my organization to connect to. I think the best way to do this is to use a web service. Please correct me if I am wrong!
Anyway, if I use a web service I need the web service(server) to connect to the database. In MS Visual studio when you add a web service project the data menu disappears and you can't add a data source to the project. There may be a workaround for this by hand coding this, but I am not sure how to do it. This is my first time working with a web service and ASP.NET so I am a real noob in this area.
Any help would be greatly appreciated!!!
Add your database connection string to the <connectionStrings/> section of the web service web.config file. Check this web site for a list of the most common database connection strings: Connectionstrings.com
You would use standard ADO.Net commands and SQL statements, rather than using the dataset designer. Example (IN VB)
<WebMethod()> _
Public Function DoesOpenCallExist(ByVal CustID As String, ByVal CallType As String, ByVal SubCallType As String) As Boolean
Dim returnvalue As Boolean = False
' first, entry validation
' snip - code deleted
Dim conn As New System.Data.SqlClient.SqlConnection
conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("HEATConnectionString").ConnectionString
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "sp_GetCallCount"
cmd.Parameters.AddWithValue("#CustID", CustID)
' Etc...
Try
conn.Open()
returnvalue = cmd.ExecuteScalar() > 0
Catch ex As Exception
Throw New Exception(ex.ToString())
Finally
conn.Close()
End Try
Return returnvalue
End Function
*This should be done
web.config file*
here the datsource is the servername,initial catlog is the databasename and the userid ur sql userid and the password is as same.
And then in the class we want to get connect with the database......
****class.cs****
public class connect
{
public static SqlConnection con()
{
String con= ConfigurationManager.AppSettings["connections"].ToString();
SqlConnection cn = new SqlConnection(con);
cn.Open();
return cn;
}
}
here the connection is the keyname......
ok i think its sufficient............