How to allow user to select an existing database or create a new one? - sql-server

We have a desktop application built with WinForms in 4.0 framework. A single user can install the application and use a local SQLExpress installation. Or, the SQLExpress can be on another machine on the network. We want to give users ability to create new database(which will execute a sql script which will create the required structure) on any server instance. Is there a control which we can used to accomplish this? Or, what are the ways to accomplish the aim?

if you're using an ORM (such as nHibernate)- then these abilities come out-of-the-box.
otherwise- you can write stored procedures that build the desired database.
this is a little more tricky, but possible.
here is a good start on DDL.

Related

Copy local SqlServer database with visual studio solution

I've created a simple sports store (From Pro ASP.NET MVC 5 freeman) that I keep on a flash drive, due to working on my desktop computer, laptop, or a lab computer on campus. Is there an easy way to bring the database tables along with it?
First, I'd recommend looking into a version control system (SVN, Git, etc). Even if you don't use it for versioning, it will--at a minimum--help you sync your code between different computers.
The simplest (yet most basic) way of bringing your database along with the code is just to add a SQL schema script along side your code and run it on the local SQL server on each machine. However, this approach has the limitation of not handling schema updates very well...which brings me to my recommended solution: use an ORM (i.e. Entity Framework) and let it handle the creation of the database. If your schema needs to change, it will automatically generate migration scripts that can update the database on your other machines.

How can I connect to my SQL Azure-database using Microsoft Silverlight?

I have a database online at Windows Azure. I want to connect to the database and show some tables in Microsoft Silverlight. I have created a Silverlight Application and published the website on Azure here!
How do I connect to my SQL Azure database in Silverlight?
The same way as connecting to any other database!
Personally, I use EntityFramework and create my own service. You can use EF and use RIA Services to create a lot of code for you though if you prefer.
Add an Entity Model to your project, create from existing db, point at your Azure Db, job done. Remember to add your existing IP to the Azure firewall while developing.
EDIT:
Try following this tutorial instead:
http://msdn.microsoft.com/en-us/library/ee707376(v=vs.91).aspx
BUT one thing to watch out for. When you come to the step to add a DomainService, if it hasn't picked up your context you will need to follow the steps listed here:
http://support.microsoft.com/kb/2745294
... which are easy to follow. Delete the TT files and change the model code generation strategy from none to default.
One thing that you can do is create a WCF project, which will act as your Web Role in Azure.
Ideally, you may have 2-3 projects in your solution:
1) Silverlight Project (Presentation Layer)
2) WCF Project (Business Layer)
3) C# Class Project for your Sql Connections (Data Layer)
What you would be able to do is use C# .Net libraries for Sql to connect to your database. You may either execute stored procedures (Can pass in variables), which are cached in memory for faster long-term performance, or Sql queries in a string variable, to pull the exact information you want in custom queries. This would be returned to the WCF Project in which you would be able to perform any custom business-logic and you may begin to package your data into class objects. These objects may be passed back to Silverlight via a Service Reference, and you may use many familiar Silverlight tools to display your information.
The above recommendation may be a more more in-depth than that of the other recommendations, but in cases where you really need control over your data and need to apply business logic, this is a good way.
The easiest way in the world I know of to hook up a SQL Database to a Silverlight application is to use a Visual Studio LightSwitch project. There are ton's of posts on how to do this - http://blogs.msdn.com/b/lightswitch/ . Basically if you make a LightSwitch application (available in VS Professional SKUs and up), it gives you several screen templates to choose from which are all Silverlight (or HTML 5 if you choose). Then you can "attach" to an existing SQL Database such as SQL Azure just fine. And make browse or edit screens around the SQL data.
You can optionally model your own SQL Database and then "publish" it out to SQL Azure.
You can do all of this without writing any code too and provides some good basic functionality.
HTH - Matt

create a database from installer file?

well for example you have build a program, for restaurant, for a cinema, wherever,
now how do you do when, you install your application, the database was installed correctly too? i dont sure but i believe this is a different database? for example a file?
(talking about sql).
and how different are going to be the queries? cuz i believe i am not going to have the same function on sql server than a file database
and what connection i shall use?
could i use entity framework?
and how capacity could to have the different file for databases?
regards
You can use a file-based database like SQLite that supports SQL queries. There are ADO adapters available as well. The link should take care of the rest of your questions as well.
Well, since you usually have absolutely no knowledge about target environment, user must configure program to his envronment at install time, or later (af first launch for example, this is much simplier than implement same functionality in installer). User specifies SQL server address (if we are talking about server-based systems) and database name he wants to use. Then database is created programmaticaly using that information.

is there a simple front for sql server?

i am in a multi-user environment
i am using access as a front end connecting to sql server database. i am allowing users to edit only one table in sql server.
i dont want to continue using access to edit a sql-server table.
can someone recommend another tool to do this?
The Access 2007 runtime and the Access 2010 runtime is free for the download from Microsofts website. Of course you'd want to purchase Access licenses for power users who want to create their own queries usually for export to Excel.
Either Access or Excel are almost certainly the simplest solutions available that meet your requirements, when you consider both the simplicity of the user interface itself and the simplicity of implementing, deploying, and maintaining the solution for the users. Creating even a simple web page isn't nearly so simple – you'll need to setup a web server, configure user security, develop the web page, etc.
Use SSMS -- Sql Server Management Studio.
Update
Found a near duplicate #SU: Less daunting front end for SQL Server
Update 2
Try to use Microsoft ASP.NET Dynamic Data. And a tutorial on YouTube, of course.
Sounds like you need to give CRUD access to a table in a SQL Server database.
Suggest making a simple page - use ASP.NET Dynamic Data. Watch this video to get started with ASP.NET Dynamic Data.
Failing that, provision the user with Microsoft Access.
setup a new user in SQL Server, and give it permissions on that table only.
setup Access to read, update, create and delete that table. Use the credentials of the user in the bullet above. This will ensure they can't mess anything else up.
Only bring that table into the user's view.
If you pull down a copy of visual studio express you could build a single screen application that allows editing a table with just drag and drop from the server explorer. No coding needed unless you're looking to add some more advanced logic.
Alternatively you could just use Access to also build a one screen front end - with that as the start up form to your Access DB your users wouldn't even know they're in Access.
Edit:
Assuming you're in a windows domain - put all your users in to a security group and then grant this group access to the SQL Server. Only grant the group permissions on the specific objects that they need to edit.
Create a blank Access DB.
Link your SQL Server table in to the Access DB - e.g. in 2007 the option is in the External Data ribbon > more... > ODBC database.
Once you have the table linked create a form to edit the data by doing Create > more > Form Wizard.
This allows you to pick the exact columns you want them to edit, pick a layout etc.
From here the options are really only limited by how much effort you want to put in but it's a good start in contrast to direct table access.
I believe it's still in Beta but you might want to also take a look at WebMatrix.

Is there a simple tool for adding users to a SQL Server database?

I'm looking for a simple tool, preferably one that I can redistribute with my application, that non-technical end-users can use to add users (and logins if necessary) to a particular SQL Server (Express) database.
Obviously SSME will do the job, but I don't want to require users to install something so heavy-weight.
I have a good idea how I would write this myself using SQL Management Objects, but I'm looking for something pre-built.
Any ideas?
To be honest, I wouldn't expect you to be able to find such a tool - the scope of it is too narrow - you want something with the power to create and edit Logins/Users, but be simple enough for laymen. Would you want such a powerful tool in the hands of such people? Apart from SSMS, there will be a number of 3rd Party clients for SQL Server, but you need something simple to use and locked down - I just don't see it happening.
However, I might be wrong - just because I haven't come across such a thing, it doesn't mean they don't exist.
I don't see why you can't build simple features into your application to add new users/logins. It seems the most sensible suggestion. Apart from SMO, is there any reason why you couldn't use CREATE LOGIN/CREATE USER T-SQL commands?
Create User
Create Login
You can write you own tool using the managed .NET Libraries SQL Server Management Objects (short SMO). They are shipped with .NET Framework 2.0 i think. So it should be no problem with dependencies.
SMO gives you full control over SQL Server. MS SQL Server Management Studio is also written based on these libraries.
edit: There is nothing, from what I can see. People normally build it into their application.

Resources