Using both oracle db and access for one gridview - asp.net

I would like to add some functionality to a gridview I have. Essentially I just want to do something similar to AutoGenerateInsert button that asp.net 2.0 does. I want the fields to push data to an AccessDataSource. The trick here though is that I want to verify some fields against an Oracle DB and even auto-populate other fields to what a user has input for a field.. As an example, my Oracle DB has personal information such as names, ages, etc. If the web-app user types in a valid name in a 'Name' field, then the field should be validated and other personal info should be auto-populated. Once all the fields are have been entered then the 'Add' button is clicked and that new record on the gridview inserts the data to an Access DB.
Any links or hints out there for accomplishing something like this?
Thanks!
-doddy

In my opinion you should store two connectionstring in web.config in aap tag
when you want to validate fields get connectionstring[0] and when you want to save field get connectionstring[1] i assume that you know how to load and save data
theres nothing complex in it.here is example
<appSettings>
<add key="dbConnection1" value="Integrated Security=SSPI;Persist Security Info=False; Initial Catalog=dbname;Data Source=servername"/>
<add key="dbConnection2" value="Datasource=servername; Initial Catalog=dbname;User ID=dbuser;Password=dbpassword" />
</appSettings>
now in code behind
public string GetconnectionString1()
{
return ConfigurationManager.AppSettings["dbconnection1"];
}
public string GetconnectionString2()
{
return ConfigurationManager.AppSettings["dbconnection2"];
}

Related

Using composite key in AspNetUsers table in MVC 5 application

I'm purposely not posting any code here as I'm really just looking for some guidance to the following problem:
I have created a three new fields in my AspNetUsers table - FirstName, LastName, and NickName. I also created a composite key using those three fields. When I try to create a new user that has all three of these fields the same, the application throws an error as expected when the unique rule is violated.
I would like it to simply post back to the Register User form indicating that the NickName must be changed to something else.
Do I need to implement a Custom User Store? Is there a simpler way?
Thank you for any suggestions.

Populating insert values in asp.net dynamic data site?

I'm using Visual Studio 2010 to create a dynamic data site with scaffolding according to: http://www.asp.net/web-forms/videos/aspnet-dynamic-data/your-first-scaffold-and-what-is-dynamic-data
The site displays a SQL table with an "Insert New Item" link, which takes you here:
I have another SQL table which holds some of the information already. I would like to add a function that is called when the user navigates away from the "account" field; the function will query the other SQL table and populate the fields that it already holds for that account.
I'm stuck on where to put the function and how to setup the account field to call it.
It's a couple of years since I did one of these so pardon the details being a bit short.
You can 'override' the default New Item form. In that you can pre-populate the fields with anything you want. I think you have to take care of the Save also, and of setting out the controls on the form and populating them (you've overridden the generated form after all).
Another possibility is to create a partial class which extends the Model class and populates it in a constructor extension (I remember doing various stuff with this technique). There might also be some extension points on the model Context (or whatever its called) which you can tap into - it's pretty flexible as I remember.

Add navigation property to Membership schema

I have an Entity Data Model for my Web Site that includes a table with some extra data for the registered users (called UserInfo). Currently, I'm setting the id of the new rows of UserInfo using the Membership.GetUser(...).ProviderKey.
What I want to do is to add a navigation property to my UserInfo table to point to the corresponding Membership row for that user but, due I have not the Membership schema in my Entity Designer, I can't figure out how to stablish this link between the tables.
Any idea?
Thanks very much,
Well, I've finally decided it's easier simply to add a property to my UserInfo table (called guid) that store the guid of the MembershipUser schema.

Single website multiple databases, database switching

I have created a content management system (CMS) for my company’s product databases. The CMS is based on asp.net scaffolding with many custom pages and actions mixed in. We have 7 products currently, all of which share the same database schema (Entity Framework model-first) and all run perfectly in the CMS. The issue is that every time we get a new product we must clone the CMS and change the connection string in the app.config to point to the correct database in order to work with the new database. While this works, it’s becoming bothersome to maintain and will fail us completely as we acquire more products.
What I would like to do is have a centralized landing page where a user is directed to log in, then given the option to connect to and edit a specific product based on their selection. The idea is that we would have one CMS site which would be able to switch between the databases depending on the user. It is not an option to combine all of the product database in to a single master product database.
I am not sure where to start to achieve this goal, or if this is even the correct plan to achieve my goal of having a single CMS to maintain, and am looking for some guidance in this.
Assuming that your database structures are identical, you could use a factory method anywhere you get an instance of your entity context and put logic in there to grab the correct connection string (or calculate it if there's a naming convention that you could use). Something like this might work for example:
public static MyDatabaseEntities CreateEntityContext(string productName)
{
string connectionString = null;
switch (productName.Trim().ToLower())
{
case "apples":
connectionString = ConfigurationManager.ConnectionStrings["MyDatabase_Apples"].ConnectionString;
break;
case "pears":
connectionString = ConfigurationManager.ConnectionStrings["MyDatabase_Pears"].ConnectionString;
break;
default:
connectionString = ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString;
break;
}
return new MyDatabaseEntities(connectionString);
}
Then use this method anywhere you need an instance of your CRM data context passing in the product name that you've calculated on your landing page.
Create another database for user to database mapping. The structure would be like so:
database UserMap
table Users
username (composite primary key)
dbID (composite primary key, foreign key to "Databases" table)
table Databases
dbID (primary key)
connectionString
Then,
populate the list of database in table "Databases"
Do your SQL work to copy the users from the other websites into this "UserMap" database
Write a trigger in each CMS database to add or remove a user as they are created or removed in their respective CMS so it updates the "UserMap" database
Modify your code on the CMS(s) to use this single database for lookup to what connection string should be used.
This would allow you to rely on the single database for the lookup and switch between them in a managed fashion going forward. It requires some up front work but after the triggers are there, you don't have to do anything more.

How to I delete an unrequired user profile property from web.config and the database?

I use the default ASP.NET Profile Provider which lets me define user properties in web.config.
I now no longer want to use one of these user properties. I want to delete all traces of it.
I can remove the property from the list of properties in web.config however, I suspect, the stored values for this property will still be held in the aspnet_Profile table for each user.
Is there an easy way to clean out all traces of the data for a property that's no longer used from the aspnet_Profile table?
Try deleting the property from the config and check the aspnet_Profile table. The value is probably not deleted. You can use SQL statement to clean the part you don't want or you could try using this which came across: http://snipplr.com/view/36547/aspnet-membership-provider--remove-unwanted-profile-properties/
Backup before you experiment :)

Resources