Uploading A SQL Server Script? - asp.net

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.

Related

Run Batch File in Asp.net C#

I am using asp.net C# 4.0
I have a batch which will open a text file.
Batch File query
ECHO OFF
start D:\accounts\request\08__processing\0377e792-4ca9-4550-b78c-de2bdf26611f.txt
ASp.net Code
System.Diagnostics.Process.Start("D:\\bacthFile.bat");
when i double click on the batch file its opening the text file.But when run above code its not opening any notepad.
it is not showing any exception also.
Please Help
Thanks
This is the wrong way to read a text file from ASP.NET, you need to use System.IO and put files you need to read somewhere where ASP.NET can get at them, eg.. App_data. That said, here is how to do it the wrong way: IIS runs on an invisible virtual window--it's a service. There is a way to get some services to display the UI, I forget how. In any case, you'd have to RDP onto the server, to see such a window after starting the service and goosing it into displaying a UI (this trick might not even work for IIS).
Next, as commenters noted, on IIS, you'll have one set of credentials different from your own (depends on what version of IIS)-- in any case, it will have restricted access and be somewhat sandboxed. If you set up impersonation and windows authentication in the web.config, sometimes you can get your request to run with your credentials.
Next, if the web host runs in medium trust, you might not be able to launch arbitrary apps from the asp.net appdomain.
Finally, the only way this could ever work is if your app is always running locally with casinni (the visual studio development server)-- but in that case, you could simplify things a lot by using a console app instead of asp.net unless you really need the HTML templating, say for output.

Export Sitebuilder SQL Server database to Excel | CSV | MySQL

I need to migrate a customer's site which happens to be hosted in a remote Win32 environment with Sitebuilder, Plesk, SQL Server and ASP or ASP.Net, I'm not sure.
I'm used to LAMP environments, so I don't know what to do with all the files in this server. Sitebuilder and SQL Server are also new to me.
I only have access to the FTP files and to the Plesk panel control, but it doesn't even acknowledge the existence of any SQL Server database (as it usually does with MySQL databases).
So far I've only been able to think of these two options:
Code an ASP script that writes down the database content into CSV files (wouldn't know where to start).
Code a script that retrieves the data directly from the HTML pages (long, painful, error prone and not useful to access data available only to logged in users).
So my question is: from your experience, knowledge of this platform, and point of view, which would be my best option?
Thank you very much in advance in my first question here. Regards,
UPDATE: I've managed to access the server (Windows 2008 server + SQL server 2008) using remote desktop. I guess I should be able to export the database now. I'll check Management Studio to see if it can help in the process.
It sounds odd that it doesn't support remote connections, but if you want to do it from within your asp-pages, the following links might be good starting points:
Want to script all objects which depend on a SQL Server table
http://www.dotnetfunda.com/codes/code32-how-to-generate-create-table-script-for-all-tables-in-sql-server-database.aspx
https://dba.stackexchange.com/questions/20355/generate-create-script-for-all-indexes

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.

How to push data from excel to SQL Server?

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.

Should I go with attaching MDF file to SQL Express or a real deployment script to SQL Server?

I am building a blog-like publishing system on ASP.NET 4.0 (with EF 4.0) that I want to be very easily deployable/backupable in the first place. I am at a decision point of whether making the system to create a database in an SQL Server and use that (traditionally), or have a App_Data MDF file in the site and just attach to that one with SQL Express. I know the memory/size limitations of Express editions, and I won't be hitting the limits as this is not a performance-critical business application or any serious stuff. Just a simple CMS with blogs/writings/photos (actual photos are NOT saved in database, just their paths are saved in MDF) and that's it. I see no problem using MDF, but I'm not an expert on the topic too as I've never worked/created a website using MDF file. I always deployed on the SQL Server, but I don't want to deal with users/roles/permissions and the last thing that I want to have a user having installation problems due to database settings.
What should I go with? Any problems that I would face with MDF? Recommendations?
IF you use SQL Server Express - which is a server - I would always opt for a "real" database approach: attach your database to the server, access it by its database name, deploy SQL scripts to update it.
That "attach DB from file path" always seemed like a half-baked and rather messy kludge to me.....
If you don't need that kind of power - investigate SQL Server Compact Edition which is a one-file only, in-process database. It has its limitations - no stored procedures, doesn't support certain data types like VARCHAR(MAX) or XML - but for easier scenarios, it's perfect and easy to use - just deploy it along your app. It's single-user, e.g. you don't share the data between several clients, it's a local store for each user/app on its own

Resources