How to push data from excel to SQL Server? - asp.net

I have written a simple ASP.NET MVC 2 application that stores data and can dynamically create excel files using Microsoft's openXML for excel files.
What is the best way to push changes the user makes in excel to my database? I know it can be done via file upload, but this is rather obtrusive to the end user to navigate to my site, select upload, and then select their file.
Is there a way to do 1 click publishing from the excel file using VBA? VBA can interact with the database directly, but this seems dangerous from a data security standpoint, and duplication of logic.
Do web services work with the MVC architecture? How do I get a vba macro enabled document to send itself to the server?

For anyone out there looking for a fix, I ended up using vba's InternetExplorer.Application object and interacting with an upload form on my site.
For more info on the upload form check out:
http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx
For more info on VBA and the InternetExplorer.Application object check out:
www.motobit.com/tips/detpg_uploadvbaie/

You might take a look at Sql server integration services for bulk upload of data into sql server. The integration services once created can be run using a normal c# desktop program or using a windows service.
But you might
need to make sure this happens in the background and will have to be
an asynchronous task.
also need to make sure it is properly secured
by not giving direct execute access to any other users

I'm assuming that this is for a specific user. I've done something very similar to what you are describing before.
Tell the user to save the excel file in their DropBox and share the file with you.
Have the server listen for changes to this file and run a server side routine to import the data.
Disclaimer: This is not a secure solution, but it's easy and will get the job done.

Related

each web online user connect with there own acces .mdb? how to do that

in my project, when a new user register online on my website, then my project create a directory on server with the user name "abc" and copy a myDB.mdb file in it.
this .mdb file contains predefined 2 tables.
now my question is :
1 is it possible to connect and use with Dataset.xsd in this task.
2 how each user read and write data with there own myDB.mdb file
3 how to make the connection string flexible. so it ll connect with each user myDB.mdb file.
I don't have any clue that how to complete it. i worked with dataset.xsd and vb asp.net but those were static dataset.xsd or predefined .xsd
JS
Oh, please don't do this. You really, really, really need to avoid this approach at all possible costs.
I strongly suggest that you install the free SQL Server Express, or MySQL, or any other multi-user database and store your data in there instead.
Doing this will preserve your sanity both when creating the initial implementation and when you have to update a column or a table in all of the MDBs that have been created for your end users.

Run a Virus Scan While Uploading files in ASP.NET

I have developed a web based application in ASP.NET and C# where users have the facility to upload files on the server through this application I want the application to Scan the uploaded files for viruses before saving on the server. Same like when we attach files with our email in Yahoo. Please guide me how I can achieve this functionality Any API which can be integrated in ASP.NET application or any other way you can suggest. We can purchase the licensed version of a product which can achieve this. I have googled but did not find specific results.
Thanks in advance!
First of all the file must be saved onto the server before you can scan it. If you notice Yahoo will upload the file first - but not allow the attachment to be sent until scanned.
Then you can use an antivirus with a command line interface or some other kind of API. Both of these can be called via C# and should provide the functionality you require. Parhaps write a wrapper class that takes a file and returns true or false depending on whether a virus was detected.
Other applications that provide you with a command line interface:
Microsoft Security Essentials
clamAv
I believe MS AV provides better results.
Just purchase antivirus software that has a command-line interface (several popular packages include this). Once the file has been uploaded, run the scan.
I would think, in order to upload and scan at the same time, you might need to implement your own antivirus software as I'm not familiar with any package that would provide that sort of interface.
I run a shareware site. It doesn't work as you described, but I download each file to my local computer and run a scan on them. You would be doing something similar.

Uploading A SQL Server Script?

My over all goal is to upload a very simple ASP.NET web site created in C# and using a SQLEXPRESS DB to a hosting provider via FTP.
I understand that I can get all of my ASPX, .CS, master pages and image files with no problem. Problem I am having and reason I am here is because I cant simply pop my MDF file into my hosting provider's (Verio Hosting) site.
On the web I ran across a post by Scott Gu. In his post he wrote about converting a MDF into a .SQL file which you can execute from a web site. See below....
If your hoster has no usable HTML web
admin tool for allowing you to easily
manage your SQL database, then you can
also just write a simple ASP.NET page
that you FTP (along with your .SQL
file) to your web-site and then hit to
read the .SQL file on the server in as
text, and then pass it as a string to
ADO.NET to execute. This will give
you the same result as the query
analyzer above - and fully create your
database for you.
I created the .SQL file and I am capable of popping this .SQL file into my website. My question to you guys is how do I create that simple ASP.NET page that I can then hit to read, and then do everything else that Scott mentioned in the passage above????
EDIT: I found out that that I can just re-create my DB by remotely logging in to my hosting providers SQL server via SQL Mgt Studio. I dont want to do this for two reasons 1.) It feels cheap knowing that there is a much cooler way to do this, and 2.) I dont know how to re-create the ASPNETDB.MDF that I use for my user database that ASP.NET created for me.
My question to you guys is how do I
create that simple ASP.NET page that I
can then hit to read, and then do
everything else that Scott mentioned
in the passage above????
Which part of the process don't you understand?
It's just a regular *.aspx web form; you do all of the work in the code behind.
BTW, when sending commands to SQL Server via ADO.NET, keep in mind that ADO.NET doesn't understand "GO" statements; if your script contains them, you will either have to parse them out and submit batches accordingly, or arrange to invoke a command-line tool like sqlcmd from your page, if your hosting provider allows it.
You simply need to have the ASP page read in the .SQL file, which is a series of SQL queries to be executed. Loop though the contents of the file, running each query in turn. The queries will create the db schema, insert the data, etc.

Is there a good way to create a recurring import for an ASP.NET site?

The site I'm working on is running Windows Server 2003 and SQL Server 8 (2000?), and ASP.NET 3.5.
I need to have some sort of script or application run to import data from an FTP'd text file, into the database. There is already a site running on the machine, that uses the current database. Can I use a scheduled task to reliably kick off some sort of .aspx page that will import the data? Or is there a better approach?
What about making sure that no one else can access the page that runs the import? I don't want random users running the import!
Thanks in advance!
P.S. some processing needs to occur on the data before its inserted. i.e. lookups, conditionals, etc, so the DB tools aren't robust enough (I think). I hate DTS, and I SSIS is not available in this version I think.
If you want to have a C# App handle your import I would suggest a windows application (exe) w/o a form (better than a console app because it does not pop up any UI whenever it runs). Have it run every so often (every minute) by a scheduled task.
Why would you use ASP.NET? Depending on the complexity of the job you could either load it directly to the database (BULK LOAD) or use DTS (SQL Server 2000) or SSIS (SQL Server 2005/2008) if more complex processing is needed.
DTS and stored procedures in a job.
BCP and stored procedures in a job.
You say you need to do alot of lookups and conversions? SQL is good at that - and good at doing it fast. It can seem a little intimidating at first, but it's not hard.
run a BULK INSERT or bcp to import the data instead, see here http://msdn.microsoft.com/en-us/library/aa173839(SQL.80).aspx
I'll echo other people here - you don't want to have a scheduled task hit a web page. SQL Server provides some good data import options, or you could just write a simple windows program and run it as a scheduled task.
Another option would be to write a windows service that watches your FTP directory and does the import.
As others have said, probably a separate console application (triggered by a scheduled task) or a windows service would be the best option for this scenario.
On the other hand, if you already have all the required functionality available in the web app running on the server, then you could probably set up a scheduled task, that starts a script (VBscript, JScript), which in turn calls a page of the web app.
To have some sort of security (e.g. preventing that any user can call that page), you could add some code to the page, that checks if the page was called with http://localhost. This would at least prevent the page from being called from a remote client.

Flex Write File

I checked in the API, that writing a file is only in Flex Air.
Despite of that, is there still a way in Flex to write a file on the server or on the client machine ?
More concretely, it's because I have a String and I will decode it by mx.utils.Base64Decoder
to a doc. And I need to open it by Word directly on the client side, or write it on the server and return the link to the client for downloading.
Thanks
I'm doing something similar - I have built a custom grid in Flex that contains an additional button on it that allows the user to open the data up in Excel. I've done this by writing a function in PHP on the server which my Flex speaks to. This creates the CSV file on the server and the function passes the link back to the client, which in turn offers the user the chance to open the data up in Excel.
I'm using the Zend technologies to accomplish this - I recommend you take a look; they're extremely good. I used to use Flex Data Services and Java do do this but just recently switched to PHP because development time is cut down drastically as a result.
Hope this helps.
Jamie.
AIR applications run on the users' desktops. They allow you to write to the users' desktops. Nothing stops Flex/AIR applications from communicating to the server, write some files there (using a suitable backend technology) and return a link back to the user.

Resources