I have an asp.net website that needs to connect to a dBase file on a remote server. The remote server has a ODBC System DSN connection configured but I have no idea how to connect to it.
The ODBC connection on the server won't help you. The ODBC Connection needs to be set up on the machine you want to connect FROM, not the one you want to connect TO.
In order to connect to the DBASE files (and treat them like a database) you will need to
Map a drive so that you can access the location of the files..
Connect use the OleDbConnection.
It ALSO deals with a problem you will have reading DBase files from .NET. If you read them often enough, the app will start throwing a "System.Resources.Exceeded" exception. The only reliable solution I've found has been to kill the app and restart it, which is done in the code named FixMyself. (Not included as it contains sensitive data). The FixMyself routine essentially starts a second exe that kills THIS exe and then restarts it.
The sample code below is copied from production code, and should give you a push int he right direction. it maps the drive, connects, and reads.
It's ugly but it works. It's also only partial as it calls several functions not included here. But again, it should be enough to get you going.
Public Function GetRegisterConnectionString(ByVal PathToFolder As String)
Return "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & PathToFolder & ";Extended Properties=dBASE IV;User ID=Admin;Password="
End Function
Public Sub ReadMyDbaseFile(ByVal DriveLetter As String, ByVal IPAddress As String)
Dim DpalmPath As String = "\\" & IPAddress & "\c$\Dpalm"
Dim cn As New System.Data.OleDb.OleDbConnection("")
cn.ConnectionString = Me.GetRegisterConnectionString(DpalmPath)
If ds.Tables.Contains("CurrentPrices") Then
ds.Tables.Remove("CurrentPrices")
End If
Dim POSAdapter As New System.Data.OleDb.OleDbDataAdapter("select * From MyDbaseFile WHERE SomeField > 0 AND ACTIVE = -1", cn)
Try
POSAdapter.Fill(ds, "CurrentPrices")
Catch ex As Exception
If InStr(ex.ToString().ToLower(), "system resource exceeded") Then
WriteToLog("System Resource Exceeded Error was thrown on register " & DriveLetter & ", IP " & IPAddress & ".")
Me.FixMyself()
Else
Throw New Exception(ex.ToString())
End If
End Try
ds.Tables("CurrentPrices").Columns.Add("LastModified", GetType(Date))
POSAdapter.Dispose()
POSAdapter = Nothing
cn.Dispose()
cn = Nothing
ds.AcceptChanges()
GC.Collect()
End Sub
Related
I have come across a bit weird problem with classic asp site which uses indexing service to search folder by given parameter and then lists files from the folder. Folder names are unique so the query should return only one recordset. Site is running at w2k8 64 environment. Before it was running in w2k3 server.
Basically everything runs okay but at some rare cases with specific folders query doesn't return anything at all. And this happens only if I go to the site from remote location. If I go to the site at localhost everything works just fine with those problematic cases.
Here is the code block
Dim strQuery
strQuery = "#all " & target & "*"
Set ixQuery = Server.CreateObject("ixsso.Query")
ixQuery.Query = strQuery
ixQuery.Catalog = "Reports" '
ixQuery.SortBy = "create [d], filename [a]"
ixQuery.Columns = "DocTitle, path, filename, size, create, directory"
ixQuery.MaxRecords = 150000
Dim util
Set util = Server.CreateObject("ixsso.Util")
util.AddScopeToQuery ixQuery, Server.MapPath("Reports"), "deep"
Sim queryRS ' Query recordset.
Set queryRS = ixQuery.CreateRecordSet("nonsequential")
Has anyone came up with same kind of problem? Any ideas how to solve it?
Update: I rewroted the program in ASP.NET because it wouldn't work as classic asp.
I have a shared folder containing a list of wav files i wish to open this files from my asp.net application.
everything is working good when we launch our application from loaclhost but after deploying it it is not workin ( it can not find files)
my code :
Dim oDirectories As String() = Directory.GetFiles("\\192.168.1.160\records\Files\" & dateC & "\", "*.wav")
Dim files As List(Of String) = (From q In oDirectories
Where q.Contains(indice)
Select q).ToList()
Dim liststrings As Integer = files.Count
ListBox1.DataSource = files
ListBox1.DataBind()
When you saying "deploying" - what do you actually mean - to a public/hosting server? Realize that you are using a private IP - which in, and of itself, doesn't always point to the problem (it's possible, depending on your type of hosting account - re: dedicated subnet), but based on the info you provided, that would be where to look first.
I am trying to read a text area (id= Message) and save it into the database. The problem is that if the user enters a single quote (') in the text, both the codes below fail to handle it.
Request("Message")
or
Replace(Request("Message"),"'","")
both fail with the error message
Security violation occurred
Incorrect value was passed for field "Message"
.
Seems like it fails as soon as it reads Request("Message")
I suspect this might be a hosting level security measure to protect against SQL injection. If this is the case the only solution might be to ask your host to disable it (and protect from this yourself) or to add some JavaScript to replace or HTML encode apostrophes when the form is submitted.
Are you testing this on a local computer or just on a site hosted with a web hosting company?
You should use a Command-object to securely save userentered data to the database.
set cmd = Server.CreateObject("ADODB.Command")
set cmd.ActiveConnection = conn
cmd.CommandText = "INSERT INTO table(message) VALUES(?)"
cmd.CommandType = 1
recordsAffected = 0
call cmd.Execute(recordsAffected, array(Request("Message")&""))
if recordsAffected <> 1 then
Response.Write "Something went wrong!"
else
Response.Write "Data saved!"
end if
The code above assumes you have an open connection to the database stored in the variable conn.
I've been working on a site to allow clients to sftp data files to us (using SharpSSH.dll) My solution works fine on my development machine but as soon as I move it to production server I am unable to upload.
I know that the problem is because my code is trying to pick up a file on the server when it obviously doesn't exist there so I need some pointers on the best way to resolve this - i.e. how do I adjust my code to allow for an sftp upload from the client machine?
The plan is basically to (and im not entirely sure that I am going about this the correct way) use my web server as a go-between so the client logs on and sftps a file to another server. Advice and pointers are very welcomed - please see code below:
transfer = New SecureFileTransfer("IP", "PORT", "NAME", "PASSWORD")
If transfer.putFile(FileUpload.PostedFile.FileName, company & "/" & filename) = True Then
lblMsg.Text = "File upload complete!"
'write data file details to table
writeAudit()
'check which account manager to alert and send email notification
emailNotify()
Else
lblMsg.Text = "File upload has failed - please try again..."
Exit Sub
End If
Public Sub New(ByVal hostname As String, ByVal port As Integer, ByVal username As String, ByVal password As String)
Me._hostname = hostname
Me._port = port
Me._username = username
Me._password = password
End Sub
Public Function putFile(ByVal localFile As String, ByVal remotePath As String) As Boolean
Try
transfer = New Sftp(Me._hostname, Me._username, Me._password)
transfer.Connect(Me._port)
transfer.Put(localFile, remotePath)
transfer.Close()
Return True
Catch ex As Exception
Dim objWriter As New System.IO.StreamWriter("C:\logfile.txt")
objWriter.Write(ex.Message)
objWriter.Close()
Return False
End Try
End Function
I have checked my sftp credentials and made sure that access from my web server to sftp server is valid and working. My log file is giving me the following exception message:
Could not find file 'c:\windows\system32\inetsrv\x.txt'.
I think I may be misunderstanding how the FileUpload control works here which may well be the crux of the problem
I'm not sure what the exact problem is but I would say that if you have tested your code and are happy it works, then this is not first place to start looking for problems. I would start with the configuration of the FTP server.
Hope this helps!
I have an application having front end in ASP.NET (VB.NET) and at back end is of Oracle. In oracle i have a procedure which generates files on two file servers (File Server A, File Server B). I have two server one is development server and the other one is client server. In my application i have a web page 'GenerateReport.aspx' which is used to generate report. On the basis of dates the backend procedure generate file on the File Server A and B. when i host the application on development server and download the generated file it is downloaded completely and when i host the application of client server and donwload the generated files only a part of file is downloaded (56KB of 97MB file). Code i use to download file is given below.
Private Sub DownloadFileClient(ByVal RemoteFilePath As String)
Try
Dim File As System.IO.FileInfo
File = New System.IO.FileInfo(RemoteFilePath)
If File.Exists Then
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & File.Name)
Response.AddHeader("Content-Length", File.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.TransmitFile(File.FullName)
Response.End()
Else
lblErrorMsg.Text = "Unable to Download"
End If
Catch ex As Exception
lblErrorMsg.Text = "Unable to Download,check file path"
End Try
End Sub
Flush the response stream before you call Response.End().
Actually, unless there's other stuff you left out, you should Flush(), but don't bother calling Response.End().