class library for asp.net applications - asp.net

We are going to develop many small applications using asp.net (c#) with oracle database. I would like to write a simple class library say dataaccess.dll that has most of the functionality for connecting to database, executing a sql query, update or insert or delete etc so that i could reuse them in my many small projects. Is there a good example online somewhere that i can get started from?
Well, probably i didnt explain my question properly..
I am not looking for how to make asp.net connect to oracle or how to execute a query (throught odp.net) from asp.net .
I am looking for ways to construct a class library with methods such as connect(),executeQuery(),insert(),update(),delete() methods which would accept connectionstring,sql query text etc as parameters from any c# program. What i want is a generalized dataaccess code or guideline to develop one based on odp.net that i can reuse again and again.
Thanks.

Search around for ODP.net which is what you'll be using. This is a helpful search term, but you'll find a lot of examples for your specific needs.
Look for pages that explain how to set up your classes to use the connector such as http://ergemp.blogspot.com/2008/10/querying-oracle-with-c-and-odpnet.html
Make sure to pay attention to the type of objects you're using to select data and don't confuse SqlDataSource with OracleConnection.
Look for pages detailing the use of the Oracle client, Oracle.DataAccess.Client.
You may know most of this, but in case someone find this question and doesn't, they get some info.

Related

Managing Azure SQL database from Azure Mobile App ( SQL-SSMS or EntityFramework)?

I'm new to Azure and started an Azure Mobile App Quick-Start (.NET) project.
I'm studying on this blog wrote by Adrian Hall:
https://shellmonger.com/2016/05/09/30-days-of-zumo-v2-azure-mobile-apps-day-18-asp-net-authentication/. However, I've been confused by the explanation saying that:
Since this is Entity Framework, I would normally need to do an Entity
Framework Code First Migration to get that field onto my database. You
can find several walk-throughs of the process online. This isn’t an
Entity Framework blog, so I’ll leave that process to better minds than
mine. Just know that you have to deal with this aspect when using the
ASP.NET backend.
On the next page, https://shellmonger.com/2016/05/11/30-days-of-zumo-v2-azure-mobile-apps-day-19-asp-net-table-controllers/
The demonstration was using SQL syntax to create/manage the Azure SQL Database, such as: CREATE TABLE... and CREATE TRIGGER... and etc.
So, my question is, with either SQL(like the blog sample shown) or Entity Framework:1) Are they both able to do the exact same stuff?2) Should I only choose one of those methods only?
All the methods discussed (code first, model first, database first) provide you with a way to create a SQL database and update the data within it. The end result is the same - a database with data.
The method you pick tends to rely on where you prefer the 'intelligence' for your data to live - with the database or with the code.
Do you already have an existing database you'll be using?
Go database first, so you can automatically generate code and classes from the database.
Do you know SQL? Do you prefer to use your database for data only (i.e. no stored procedures or validating data inside the database)?
Go code first, you have full control of your model from the Code, and its a bit easier to keep databases in sync with your application.
There are a few more considerations that can help skew you to a different method. You can take a look at this blog post from Roland about the pros and cons of each approach.
There's also a StackOverflow thread that summarizes the differences between the methods.

ADO.Net - Fetch multiple values from database

I'm new to Dotnet, can someone please advice - I want to write a CLASS LIBARY which will help multiple functions and they will fetch values from database. This CLASS LIBRARY would then be compiled as DLL and given to other apps to use.
Can anyone provide me link - where I can find good samples of Ado.net or can anyprovide working code which shows me how to fetch multiple or single values from database (writing all this in class library)
Regards
ADO.NET #MSDN is a good starting point.
CodeProject features a good tutorial.
Check this out: Retrieving and Modifying Data in ADO.NET
If you already know how to create and open a connection to database, then read this section: DataAdapters and DataReaders
Go to http://www.w3schools.com/, it will be help lot of can you do better.

What is better for my ASP.NET project using (Server explorer) or DBconnect class?

I have ASP.NET project and I want to know what is better to use.
ODBC connection and with Server Explorer (drag and drop make DataSet and modify it) or do some DBconnect class with connection to database, queries and use it for GridView?
When I use server explorer, I don't have good feeling because all logic is on aspx page and I do not separate from the application layer logic layer.
It will be a lagre application, databese(PostreSQL) have 18 tables and difficult constraints and application have to generate some documents etc. .
"Better" depends entirely on your situation. Is the purpose to get something done as quickly as possible for internal users at your company, or is this going to be a commercial site that will need to be highly extensible and needs to be as easy as possible to maintain? Will you need to integrate with other platforms possibly built using other languages at some point? The answers to all of these questions should affect your decision.
If you're looking to separate your project into distinct layers, then I would recommend an ORM such as NHibernate or Entity Framework (there are other commercially available ORM products out there, but these are the ones I'm familiar with and which you can easily get help with on this site).
Create a DataSource with LINQ to Entity. It let you the liberty of LINQ with the peace of mind of when you change something il will break your build so you will be able to debug more efficiently.
Well if you have total flexibility, I would recommend using C# ASP.NET 4 with MVC3 razor for the UI and application code. Use Entity Framework 4.1 code first for the data access layer.
This way you will always work with real objects that you create, and with List<realtype> instead of the total mess that exists with datasets.

.Net Custom Libraries?

Where can I get custom libraries for ASP .Net? Specifically I am looking for ready made database access library that allow me to select, insert and update a database using transactions. I know how to do create but I am trying to use an existent library that does all that and handles exceptions and errors so exempt from the hustle of creating that from scratch and go into errors.
You can use Microsoft's free Enterprise Library for DataAccess, Logging, Caching, Security and Configuration. It's very commonly used.
Also you can use code generators like free .NET Tiers, but you will need CodeSmith if you want to use it.
I'd suggest looking at either using LINQtoSQL and the DBML designer to map your database tables onto objects in your system or a more full-featured ORM, like nHibernate.
You may want to look at something called Speedy.net. I have never used it, but it looks interesting. I have used other code that these people have written, and normally it's pretty good. For the small amount of money that it costs it might be worth trying out.

Need advice on selecting a data access method

I am in the early stages of planning a conversion of a large classic ASP database application to ASP.Net and I'm having trouble picking out which data access method to use. I have played around with Linq To SQL, Dynamic Data, strongly typed datasets, Enterprise Library (Data Access Application Blocks), and a tiny bit with Entity Framework, but none of them have jumped out to me as "the one". There are just too many choices - my head is swimming, help me choose!
Perhaps it would help to give some background on the application that I am converting along with the priorities...
The back end is Microsoft SQL Server (2005 or later) and we are committed to that, so I don't need to worry about ever supporting a different database platform.
The database is very mature and contains a great deal of the business logic. It is highly normalized and makes extensive use of stored procedures, triggers, and views. I would rather not reinvent two wheels at the same time, so I'd like to make as few changes to the database as possible. So, I need to choose a data access method that is flexible enough to let me work around any quirks in the database.
The application has many data entry forms and extensive searching and reporting capabilities (reports are another beast which I will tackle later).
The application needs to be flexible enough to deal with minor changes to the database structure. The application (and database) may be installed at different sites where minor custom modifications are made to the database. Ideally the application could identify the database extensions and react appropriately. In other words, if I need to store an O/R mapping in the application, I need to be able to swap that out (or refresh it easily) when installing the application and database at a new site.
Rapid application development is critical. Since the database is already done and the user interface is going to closely match the existing application, I'm hoping to find something where we can crank this out fairly quickly. I am willing to sacrifice not using the absolute latest and greatest technology if it will save time in development. In other words, if there is a steep learning curve to using something like Entity Framework, I'm fine with going something like strongly typed Datasets and a custom DAL if it will speed up the process.
I am a total newbie to ASP.Net but am intimately familiar with Classic ASP, T-SQL and the old ADO (e.g. disconnected recordsets). If any of the data access methods is better suited for someone coming from my background, I might lean in that direction.
Thanks for any advice that you can offer!
Look at all three articles in this series:
High Performance Data Access Layer Architecture Part 1
Great advice.
You may want to look at decoupling the database layer from the asp layer so that you can not only give more flexbility in making the decision, but when you have to make changes to a customer's database you can just swap in a new dll without changing anything else.
By using dependency injection you can use xml to tell the framework which concrete class to use for an interface.
The advantage to doing this is that you can then go with one database approach, and if you later decide to change to another, then you can just change the dll and go on without making any changes to other layers.
Since you are more familiar with it why not just go directly to the database at the moment by making your own connections? Then you can move the rest of your code and along the way you can decide which of the myriad of technologies to use.
For a new application I am working on I am starting with LINQ to SQL for it, mainly because development will be quicker, but, later, if I decide that won't meet my needs I will just swap it out.
nHibernate might be a good fit. You can store the mapping in external configuration files which would solve your needs. Another option might be using ActiveRecord, which is based upon nHibernate.
nHibernate has a neat feature which you might find helpful. It's called a Dynamic property which is basically a name value pair collection populated by pulling the column names from the mapping file. So when you add a column at your client site, you update the mapping file and you'd be able to access the data through a collection on the object.

Resources