I have a Web Application (Netbeans 7.2, Glassfish 3.1, PostgreSQL 9.1) where each my customer has it's own database (all databases are identical in structure).
I need that at login the application change the database connection (and entityManager) to the relevant one for the customer.
The initial (default) connection parameters are defined in "glassfish-resources.xml" and the associations Customer-DatabaseName are defined in a text file (all databases resides in the same server).
How I can manage a different connection for each customer?
How I can close the default entityManager and create a new with a new db connection?
Thank you very much.
Related
I built a MVC site with Identity that will be replacing an old site that uses Asp.Net 2.0 security. I used a local database to create all of my pages. I'm finally at a point that I want to use my hosting provider's SQL Server. I published my code and changed the connection string to point to the hosted SQL Server. Migrations are turned on and I even ran "Update-Database". However, I don't see tables like "AspNetRoles" or "AspNetUsers". I went ahead and changed the connection string on my local machine to point to the hosted SQL server to make it easier to test out. I tried logging in with one of the accounts I created previously and it said it couldn't be found. That's actually a good thing since it tells me that it's pointing to a new database. I went ahead and created a new user hoping it would auto create the database tables. The new user worked and I can log in with the account but I still can't see the tables when I look at it through SQL Studio Mgr. Yes, I did refresh the tables under SQL Server and still don't see them. Any suggestions on why I'm not seeing the Identity tables?
I am new to the MVC world, i am developing an mvc5 code first from database project which i want to to create securely connection between my local server with more than one sql servers, and each server can contains one or more databases.
so can someone clarify me these:
1. Creating SQL Server Connections[if possible in one entity framework]
2. Securing the Connections.
3. if possible how to access the database other then the initial catalog database
Note:
i found to use entity framework to data access , after creating connection then encrypt the connection string by command-line utility, Aspnet_regiis.exe
any other techniques rather than this.
Thanks
As far as securing connections go, all you've got is SSL. Make each SQL Server instance only available via SSL and your connection is as secure as it will ever be. Encrypting the connection string, using a limited access user, etc. are important, but aren't really aspects of securing the connection, merely security in general.
For multiple database access via Entity Framework, you just need multiple contexts. Each context belongs to one and only database, but you can have as many contexts as your want. The only thing to be somewhat mindful of is having multiple contexts that you run migrations against. While I believe EF has supported this since version 6, it's still not recommended. Generally, you should only have one context that you run migrations against (the entities that inherently belong to your application), while your other contexts will merely work with existing database created and managed outside of your application. Really, if you think you have a need for multiple migrate-able context in a single project, that's really an argument for splitting up your project into multiple projects.
So, for connecting to an existing database, you just need a regular old DbContext subclass, with a couple of tweaks: 1) you need to specify the connection to use manually and 2) you need to disable database initialization. Here's a skeleton of what that looks like:
public ExistingDatabaseContext : DbContext
{
public ExistingDatabaseContext()
: base("ConnectionStringName")
{
Database.SetInitializer<ExistingDatabaseContext>(null);
}
// DbSets here
}
I'm searching for information on database connectivity (Firebird in my case) with IntraWeb Applications.
I especially need to know the difference(s) involved in using the database on the TDataModule with LockDataModule function, or using the database on the UserSessionUnit.
For example i need to have the database totally disconnected if no users are using the server, and at most 30 users will be connected.
I may at worst have to connect to some old paradox Database and i need a structure that could handle that (i know that i'll have to generate a folder based on WebApplication.AppID to handle sessions). At worst...
Thanks in advance for any piece of information or useful links you could provide me ^^
Scenario 1 - You leave "Pool Data Connections" unchecked in the Intraweb Application Wizard
In this scenario the wizard creates a ServerController, a UserSession but not a DataModule. You place your database, session and dataset components on the UserSession.
Whenever a new user connects to your website a new instance of the UserSession is created and a connection to the database is made. When the ServerController.SessionTimeOut expires due to user inactivity the UserSession is destroyed and that particular connection to the database is severed.
For 30 concurrent users this model will probably be fine for you and should guarantee that all database connections will be severed when the website is not in use.
Scenario 2 - You check "Pool Data Connections" in the Intraweb Application Wizard
As well as the ServerController and the UserSession the wizard will create an empty DataModule. You place your database, session and dataset components on the DataModule.
The ServerModule has a TIWDataModulePool component on it which has PoolCount property.
When your application starts it creates PoolCount instances of the DataModule each one of which makes a connection to the database. As your pages require database access they call LockDataModule and UnlockDataModule to temporarily make use of one of the DataModule instances from the pool.
When your application closes the DataModule instances in the pool are destroyed and their connections to the database are closed.
This model is appropriate when having an open database connection per user would exceed the capabilities of your database server. For just 30 users connecting to a FireBird database I don't believe it would be required.
You may want to consider using a component set like kbmMW by http://www.components4programmers.com/ I have used this for years with Desktop apps ans now with IW apps. I deploy my apps as Services and currently having a few issues deploying as an ISAPI. kbmMW is well suited for an app with lots of connections as it offers connection pooling etc... It has many features and benefits. Check out site for yourself.
I use the Enterprise version, though I think the free version may be useful to you.
Cheers!
-Lou
so I'm developing a SAAS application using asp.net mvc SQL server 2008 and Linq2SQL I've a master db where I'll store information about clients like name subdomain/hostname information and other stuff and I'll use one database per client for the actual client data,
what is the best way to generate and use the connection string for each individual db the connection string will be based on each customer domain so I could hard code it into master db at customer creation and create the DataContext based on that? any flaws in this strategy?
I am also using forms authentication and it will be built into each clients own db so do I've add anything dynamically to the configuration? as currently the authentication/membership is driven by connection string inside the web.config file
You should probably have a table in a centralized master db that includes the database connection information for each client. Then in your SAAS application, any time you are instantiating the data context, instead of using the default parameterless constructor, use the constructor overload that takes the connection string you stored in the centralized database for that client. The context shouldn't be kept alive between requests, so you shouldn't have a problem with cross page requests across multiple clients.
We have a requirement where a Grails application is required to connect to an external SQL Server 2005 (i.e. client's database server via a linked server). Our grails application will have its own SQL Server database instance for user authentication (so will mostly have only one domain class) and then it needs to connect to the external SQL Server database to fetch (only SELECT permission provided) data from 10 or 15 tables (out of 250 tables available) and show it the grails application.
I would like to know would be the best approach to take in this scenario.
Thank You.
Jay Chandran.
You can use the http://grails.org/plugin/datasources plugin and configure the external server as a read-only datasource to ensure that only reads are performed. If you don't want to map domain classes on that server you can use groovy.sql.Sql to execute SQL queries.