Use DataContext.CreateDatabase in SQL Azure - asp.net

I am trying to re-deploy my ASP.NET MVC3 application across several different environments and would like to try using SQL Azure. I'd like to use my existing LINQ structure and CreateDatabase to create these databases.
I am wondering how I can use CreateDatabase with SQL Azure since the USE statement doesn't work on the platform.
Please answer with any suggestions or if there might be a better way to do this.

http://msdn.microsoft.com/en-us/library/ee336274.aspx
Important: The CREATE DATABASE
statement must be the only statement
in a Transact-SQL batch. You must be
connected to the master database when
executing the CREATE DATABASE
statement.
You'll have to find a way to fit in this premise. Maybe it's not possible.

Have you actually tried executing this?
I've deployed nHibernate apps to SQL Azure - these apps call CREATE DATABASE somewhere inside the nHibernate layer and they work OK.
Best advice I can give is to try it - then come back with any specific errors you see. There may be some changes to make, but I think these should be small.

Related

Windows Work Flow persistence database?

Few questions:
1. Is SQL server installation needed to run Windows Work Flow?
2. If yes, where does work flow stores (persists) data for a long running process
3. I see that some files are created in .\windows\Microsft.NET\Framework\v4.0\SQL\en\ (some sql scripts to create persistense points)
4. Do we need to run these scripts to manually create database?
5. Can we persist data on file system instead? so that we don't need to install SQL Server?
Thanks
I see one supposed answer already, but "read the docs" answers really aren't good answers, especially in an area so poorly documented as WF, so in case anyone else stumbles across this thread:
(1) SQL Server doesn't have to be installed just to use workflows, but if you want persistence for long running workflows, (2) SQL Server is your easiest way to get it.
(3) and (4) You can let AppFabric do most of the heavy lifting in setting up the persistence database for you.
(5) you could persist on a file system instead of SQL Server but IMHO, from what I've seen in my short time with WF and persistence so far, you'd be crazy to try to implement your own persistence provider like that, especially when just starting out. You can use SQL Server Express to get started. Why reinvent the wheel?

ASP.NET - Is there an object that I can execute sql queries against?

I'm developing an application in asp.Net using VB and an Access database. My client has specified these, and I can't use more robust tools.
My application has to perform a sizable number of logical operations, and SQL is perfect for this. However, because of some of the limitations of Access SQL, I can't really write large SQL statements that do the whole job. Lacking logic testing like IF-ELSE, I'm stuck writing literally dozens of SQL statements. That would be OK, but I'm leery of all that activity against an Access database. Access isn't very stable when you work it that hard.
I've fooled around with funky solutions using things like the SWITCH function, but they look more like spaghetti than actual code. Wouldn't be maintainable at all.
I can upload all of the data into objects in memory and loop back and forth through them using VB logic, but SQL would sure be more efficient.
My question is: is there some object I can create in memory that I can run SQL against? Some recordset-kind of thing? Came up snake-eyes when I searched for this, but I thought I'd ask.
Thanks for any suggestions.
So if I understand your question correctly you currently have to use an Access database as the backend storage but you do not like doing this and would rather pull all data into the application (ASP.Net) and perform your queries against this as if the database was an SQL database in the application. I expect then that you would push the data back.
AFAIK no this cannot be done. While you could put most of the data into objects and do the manipulation there you will not have the relationships etc. but you could try using LINQ or entity framework.
This link below explains that you can do LINQ with MSAccess and that may give you the query power you want.
Query Microsoft Access MDB Database using LINQ and C#

How to sync two ASP.NET Membership databases

I have a local and an azure ASP.NET Membership database. I need to be sync them both. Wondering if anyone has found a easy way to do this? The table structure seems simple enough but would rather pull from azure than push. Is there a routine or tool I do not know about to do this by now?
Thanks
-Ken
This would be a suitable job for the Microsoft Sync Framework.
You create a service or scheduled task that makes the necessary calls. Have this running on your server and you can pull from the Azure database and sync with the local one. It can be set up to sync one way or two ways.

ASP.NET MySQL WebApp Architecture

I'd like to know the best architecture.
We have a web application running different domains. Each domain has its own MySQL database but the db structure is the same for all of them.
We have a web application for the visible part of the application.
We have a dataLogic project
We have a dataEntities project
We have a dataAccess that contains only the methods to connect to the data base.
Before we called stored procedures on a database. But we had to change it because the performance was bad. Also, the problem was that every change we made we had in a stored procedure we had to copy to every database.
We are thinking in using a WebService to retrieve the data. Every domain can call the web service with a connection string and connect its database to retrieve data. This way when we change a SQL query we only have to compile the webService and change it, we don't have to change versions on multiples domains.
Also, what do you think about the SQL queries? Since we don't want to keep using stored procedures, what is the best way to do it? Directly from code?
Thanks
T
If you have multiple Database servers you will have to make Structural changes from one DB to another one way or another. There are many tools to change Database structures. These tools will look for differences between Schema, and will either generate the SQL code for you, or do the changes by itself (it depends a lot in the tool, there are powerful ones and not so powerful ones). Please do take a look at Toad for MySql. Now, for the Data changes, you may want to replicate the data from one Database to another. This is done through Replication.
We are thinking in using a WebService to retrieve the data. Every
domain can call the web service with a connection string and connect
its database to retrieve data.
This sounds like a good idea and since you already have "dataAccess" and "dataLogic" projects, it should not be too hard to make the services.
Also, what do you think about the SQL queries? Since we don't want to
keep using stored procedures, what is the best way to do it? Directly
from code?
I don't think it is a good practice to have the SQL queries directly into your code, but it depends in a lot of things, so I would suggest Stored Procedure vs Hard-Coding the queries, or LinQ (Entity Framework 4.1).
Good luck with your project and I will take a look at this thread frequently to see what you end up doing.
Have fun!
Hanlet

SQL Server console like control for ASP.NET

I'm deploying a web site and I need to run large TSQL scripts contained in a single file in a production server where I don't have full access to SQL Server console and I can't connect remotely. The scripts is a mixed of table, stored procedures and views creations. All I can do is to run 1 group of TSQL sentences, like the ones for a stored procedure.
I have two options: to parse the file manually looking for GO's sentences and run each block of sentences before that GO, or to do the same task but with a tool. Using a tool I will be very fast doing the task, but I don't know any tool such that.
Do you know any tool that I can use?
I think it must be something like a control, with an editor where I will paste or load the scripts to run, and it will be able to parse and run them in sequence, like the Microsoft SQL Server Management usually does.
You could check out some articles on CodeProject on the topic and maybe use one of those tools / component for your needs?
Universal Database Admin for ASP.NET and SQL Server (Reloaded)
ASP.NET Database Admin Control
Web SQL Utility
Most of those come with full source and could also serve you as a starting point for a custom version of your own.
Marc
you got many options
usually i create stored procedure in sql management studio then save it as string, then use linq2sql to execute the stored procedure, works very well.
use sql server smo object where you can really do mostly many things like creating DBs, tables, it is really cool, i create 1 page on my site and use it to update DB with it.
here is a good link for that
http://www.sqldbatips.com/showarticle.asp?ID=34
you can use Redgate SQL data compare, and Compare. they rock really to synchronize DBs, it have saved me a lot of time and it is super easy, highly recommended really.
hope this helps.
If those don't work, it's pretty easy to write such a tool yourself. Just use Regex.Split to split the text on the GO lines, then loop, calling ExecuteNonQuery for each section.

Resources