user209898
user209898

Reputation:

SQLConnection Objects Declarative vs C# code

I am curious about developer opinions regarding creating and using SQL connection objects.

We are transitioning our software application from ASP to ASP.Net, i.e. new features are being added using .Net.

We have created SQL Connection objects through C# code and and through the designer which declares the connection object in asp markup. We've also created the connection object bypassing the designer and just coding the asp markup. We can add parameters and SQL statements to the asp designer/markup that make the connection object quite usable for the application... or we can do this through code.

What are the opinions of experienced .Net developers on the options for creating and using the connection object. Pros/cons for using c# code vs. the asp interface (design tool and markup).

Upvotes: 0

Views: 197

Answers (2)

Jason Berkan
Jason Berkan

Reputation: 8894

You should be declaring your SQL connections as far away from your UI as possible, which means they should be done in C# code. You should have a data access layer that is responsible for loading stuff out of the database, and that layer should contain the connection objects.

Using the markup ties your data access directly to your UI and makes it difficult to separate the UI from the data access code.

Upvotes: 1

vladhorby
vladhorby

Reputation: 378

Design tools are nice for quick examples or demos. However, having the connections and statements at the page level would affect your layered architecture. You'll probably need to create the SQL connections in the backend, in a data access layer.

Upvotes: 1

Related Questions