|
i've this application that reads multiple files from a folder and upload them to the server..it works fine but when it wants to upload each file, it creates a connection, upload the file and closes the connection. it does the same thing for all the files over and over again. i want a situation where it creates just one connection, upload all the files and close the connection. please any help will be appreciated, i searched everywhere but couldnt find any help. below is my code
Imports System.IO
Imports System.Net
Public Class DemoFTPServerApp
Dim _Filename As String
Dim _UploadPath As String
Dim f As String
Public Sub LoadFiles(_User As String, _Password As String, _Path As String)
Dim _MyArraylist As New ArrayList
Dim FolderPath As String = "C:\Users\Desktop\files"
Dim finfo As New DirectoryInfo(FolderPath)
For Each fi In finfo.GetFiles("*.txt")
_MyArraylist.Add(fi.FullName) 'full path only
_Filename = fi.FullName
f = fi.ToString()
_UploadPath = _Path & f
Try
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(New Uri(_UploadPath)), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.UploadFile
request.Credentials = New NetworkCredential(_User, _Password)
request.UseBinary = True
request.UsePassive = False
request.KeepAlive = True
request.ConnectionGroupName = "company name"
request.ServicePoint.ConnectionLimit = 4
request.ServicePoint.CloseConnectionGroup("company name")
Dim buffer(1023) As Byte
Dim bytesIn As Long = 1
Dim filepath As System.IO.FileInfo = New System.IO.FileInfo(_Filename)
Dim _FileStream As System.IO.FileStream = filepath.OpenRead()
Dim _Stream As System.IO.Stream = request.GetRequestStream
Do Until bytesIn < 1
bytesIn = _FileStream.Read(buffer, 0, 1024)
If bytesIn > 0 Then
_Stream.Write(buffer, 0, bytesIn)
End If
Loop
_Stream.Close()
_Stream.Dispose()
_FileStream.Close()
_FileStream.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Next
MessageBox.Show("File Succesfully uploaded!")
End Sub
Private Sub btnUploadFile_Click(sender As Object, e As EventArgs) Handles btnUploadFile.Click
LoadFiles("username", "password", "ftp://ftpsite.com/")
End Sub
|
|
|
|
|
Hello !
In a vb.net program that use a sql server database , is there a way to keep the database file in Program's folder instead of default sql server's Data folder ?
Thank you !
|
|
|
|
|
Yes, but the Program Folder is not meant for data, it is meant for applications. Data goes in the users' documents folder.
It may require administrative rights to make modifications in the Program Folder; meaning that any user using it would have to run in an administrative role.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|
Depends on your client; in my case you'd need at least bribe the sysadmin, otherwise there will not be a folder in the root of the drive. Also, data is "expected" to be in the documents folder for both backup-applications as well as migrations.
If you "create database", you have multiple options on where to store you datafiles and how large they are allowed to become. More info on MSDN[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Everying under Program Files is read-only to to normal users. It's not a good idea to put your database in there.
|
|
|
|
|
My program folder is something like this : c:\MyProgram1.
And let's says that there's no problem about permissions.
What else should I do to realize that scenario ?
|
|
|
|
|
Putting your program off the root of C: will just piss off system admins. Permission control becomes an issue with them and results in more work.
Unless the SQL Server is local on the machine, you really don't have control over where the file goes.
But, if it is local, you have to execute the query to create a database manually and tell SQL Server where to put the files. Assuming SQL Server, you have to attach to the master database in your connection string and then execute the following SQL against it:
CREATE DATABASE MyDatabase
ON
( NAME = N'MyDatabase_data',
FILENAME = N'C:\MyProgram1\MyDatabaseData.mdf',
SIZE = 100,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5 )
LOG ON
( NAME = N'MyDatabase_log',
FILENAME = N'C:\MyProgram1\MyDatabaselog.ldf',
SIZE = 100,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5 )
All sizes are in MB by default. You can read up more on the CREATE DATABASE statement in the documentation[^].
|
|
|
|
|
If it's an existing database:
1) "Detach it" in Management Studio
2) Copy from the default location to the desired location
3) "Attach it" in Management Studio from the new location
|
|
|
|
|
Ok , but your steps are not the real scenario that I want.
- I have the program folder.
- The databases are inside the program folder.
- I open the program.
- The databases should be attached from the program automatically.
- When I close the program the databases should be detached automatically
|
|
|
|
|
"Connection strings" are used to "connect" programs and SQL Server databases.
You do not seem to know the difference between "attaching" a database to SQL Server and "connecting" a program and a database.
|
|
|
|
|
I want that the databases to be not be visible under SQL management studio , when my program is not open.
|
|
|
|
|
desanti wrote: I want that the databases to be not be visible under SQL management studio Well that is not going to happen, you can't manage the SSMS application in your app.
What you can do is set permissions on your database so it requires credentials to OPEN your database. It will still be visible but non credentialed users will not be able to access it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Sorry , but you get just a part of my words and try to comment them as you want.
I've said :
Quote: I want that the databases to be not be visible under SQL management studio , when my program is not open.
This is the full scenario :
- My program is installed on the client's computer.
- The databases are on my program folder ( not in default sql server's data folder )
- At this time the databases are not visible on Sql server management studio.
- I open the program , and at this point I want to attach my databases.
- After I connect to these databases.
- When I close the program , I want to close the connection with databases.
- After I want to completely detach them , so they will not visible on SQL server management studo.
Is it possible to realize this scenario ?
Thank you !
|
|
|
|
|
Actually you don't understand how a database management system works.
In SSMS a database needs to be attached to the server, any user with adequate permissions can attach a database including yours no matter where it resides. You cannot stop a user from attaching a database!
You can stop a user from accessing your database using the standard security functions in SQL Server.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
Is it possible to separate each project's form in different dll files , and to call them when needed ?
To be more clear , currently when the project is compiled , an .exe file is created and all the code related to different forms are inside the .exe.
Is it possible to change this behavior , so on exe to have only the main's form code , that just call other forms from dll files ?
Thank you !
|
|
|
|
|
Yes it is but at a cost of increased complexity.
You'd have to create a class library project for each of your forms. The class files in those projects should be changed immediately to inherit from System.Windows.Forms.Form. It's then possible to open them up in the designer and drop controls on them.
You're also going to have to change the InitializeComponent() method in each of those forms from "private" to "public" so you can call it from the calling form. This will setup the controls on the new form so that they are visible.
You then have to go back the project that's going to use this form and add a project reference to each of the forms that this form is going to use. You then can create a new instance of the form but you're going to have to initialize it yourself, something like this:
using (var newForm = new Form2.Form2())
{
form2.InitializeComponent();
form2.ShowDialog();
}
I don't see any benefit that outways the complexity of doing this, so what's the point?
|
|
|
|
|
I have some reasons , but maybe I'm wrong , so I need an opinion :
1) Different people take care programming of different forms
2) Some time 1 clients want some changes in one or same forms that don't affect the remaining forms. So they can be prepared as dll's and installed to only these clients.
3)The project use a database. In general the database is the same for all clients. But sometimes some clients ask for changes on database that affect the controls in one or some forms. But not all clients wants this. So we can prepare the corresponding database and dll's for these clients only and installed to them.
4) The forms contains some Entity framework queries , that may be different for different clients.
|
|
|
|
|
Separating this stuff into their own projects may work, but as I said before, it just adds complexity to your project structure and makes it ridiculously easy to ship the wrong .DLL's to the right customer.
What solves these problems is version control, like Git, SVN or TFS. Branching of the source lets you create multiple custom versions of the source code that can share code as well as isolate each branch from the others so you don't end up shipping the wrong executables to the customers.
|
|
|
|
|
Dave Kreskowiak wrote: I don't see any benefit that outways the complexity of doing this, so what's the point? I've seen the discussion in the Lounge.
Modularity comes to mind; if the interface to show the form does not change, one can easily update the dll without touching the executable. Doesn't mean that you should go ahead and put every class in a separate dll without thinking - that way the added complexity becomes unmanagable, without providing any benefits at all.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you !
But each form has a specific purpose.
And in general the forms for different clients are similar.
But for example :
One client need some extra fields in database , and of course need some extra controls on the form , some modifications to Entity framework queries , some extra/less columns in a datagridview...etc. But of course that I don't know this on the beginning , the client may ask for these modifications time to time , so I need way to update different clients with different modifications that they ask.
So in this case , I think to use separate dll for each form class.
If someone knows a link where I can see a simple project that use this idea , would be helpful , or this is not a good idea , and someone knows a better solution ?
|
|
|
|
|
Any example that shows how to create a separate project, add a reference, and invoke a form would do.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I wrote a program that is now in use by quite a few friends and over the past few years, I've updated the program with additional field added to tables I need to develop a program that will make these change without me going to them and doing this in person. Can some one help me.
|
|
|
|
|
How can we help?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Well, you haven't said anything about what you need help with, so I'll give you a large hint.
All SQL database engines are manageable by executing SQL statements against them. That includes security, adding/deleting indexes, tables, columns, and obviously rows.
So, you just come up with the SQL statements to make the required changes to your tables/columns/rows and execute those against the database.
|
|
|
|