C# - Best Way To Deal With DB Connection In The DAL - Create Or Pass?
Jan 26, 2011
I want my Data Access Layer to be built very modular.Therefore I have data retrieval methods that sometimes are called directly from the business layer and sometimes are called by other data retrieval methods to create object dependencies.What is the best way to deal with database connections in the DAL?
a) Create a new connection in every method and dispose it afterwards.Good: Easy to write and to work with.
Bad: Many connections are being opened and closed. (performance?)
b) Pass the connection as an (optional) argument.Good: I could reuse an open connection for multiple commands.Bad: I have to keep track of the ownership of the connection (who has to close it?) and cannot use the very neat "using" statements.c) Something else? (Connection as singleton maybe?)This is the first time I am writing a real DAL so I really could use some help from you experienced folks.EDIT: As it seems to matter, it's an ASP.Net Website Project.
View 5 Replies
Similar Messages:
Mar 7, 2011
using vb.net/asp.net 2005.
I am trying to pass a sql connection object by reference ("ByRef") like so but when I'm inside the function that i'm passing it to it sees the connection as closed, what am i doing wrong?
[Code]....
View 1 Replies
Apr 6, 2010
I would like to do a connection of asp.net page with Sql Server. Here I would like to read the Windows user account name and pass in the connection.The connection should be Windows authentication. IIS server and Sql server are installed in different machine. Here I am able to connect locally, When I am running from server, It takes windows account of Server.
so i can read local account(Where user is accessing the web application) and make windows authentication sql server connection.
View 3 Replies
Sep 13, 2010
I'm using Visual Studio 2008, and my database is SQL Server 2000.
I want to add a connection to the Server Explorer in VS. The Data source is Microsoft SQL Server (SqlClient). After entering in all my information and I click Test Connection, it is successful.
But when I click OK, I get the error:
Unable to add data connection. ExecuteScalar requires an open and available connection. The connection's current state is closed.
View 3 Replies
Apr 13, 2010
this is my requirement
1 receive an xml string
2 data procress (retrieve data from db ãupdata from db ... )
3 return an result of xml string
this the way I did
1 receive an xml string
2 parse xml by this way
string NO = xml.GetElementByTat("NO")[0].InnerText;
string Name = xml.GetElementByTat("Name")[0].InnerText;
use data to active with Database
ex: select Manager from deparement where EMPNo = 'No' and EMPNAME = 'NAME'
3 return an result xml to the who call webservice
string rtnXml = "<ProjectTeam>"
+"<No>A121</NO>"
+"<Name>Jack</Name>"
+"<Manager>Allen</Manager>"
+"</ProjectTeam>";
like this... but sometimes this way is mass.. do you have other idea to deal with xml ?
View 3 Replies
Feb 9, 2010
If one file is used by other process and you are trying to manipulate with it...it gives an error:-
The process cannot access the file 'abc.txt' because it is being used by another process.
In C#, How can i come to know that 'abc.txt' file is used by the process Name "XYZ.exe" (or any other process)?
View 1 Replies
Aug 15, 2010
Is it possible to create a wap having a mssql connection?
View 1 Replies
Dec 13, 2010
There is one oracle 11g server, I want to create connection from my .Net project. tell me the steps which I need to follow for create connection.
View 2 Replies
Jan 14, 2011
I have two tables that effectively have a many to many relationship between them. Effectively I want to perform a query that returns results just from Table2. For simplisity table2 has 4 fields: theId, ForeignId, Info, extra
In table2 there can be multiple records with the same value of ForeignId (but each will have a unique theId which is the tables primary key).
I want to perform a:
select top (1) * where ForeignId=x order by extra
which will select 1 record for a given ForeignId
However, I then want to wrap that within an outer query where I have a list of foreignId (ie where ForeignId in ListOfX) but I want to return 1 result record for each value of foreignId. Does that make sense? So the result will be a set of records with one record for each value of foreignId and that record would have 'info' from the top(1) record from the inner query.
View 3 Replies
Mar 8, 2011
ite on dataset model and I used to write sql quires into dataset and call them with in my c# code as usual. and used the datatablein c#code to access the values of each column which corresponds to a sql column in the sql table. after a while I found my website going on too slowso I decided to use linq to sql classes. i can write queries in c# code
[Code]....
View 4 Replies
Jan 20, 2011
How to create a SQL Server 2005 connection string .... if my site path on server is
[URL]
View 1 Replies
Mar 14, 2011
I am new to Visual Studio 2010 and ASP.Net, and when I first connected my SQL Server to Visual Studio it created huge files full of my SQL classes (maybe this was LINQ classes), and I accidently deleted/corrupted those files, and now I want it to create those classes again. Can someone tell me how I can do that?
View 5 Replies
Sep 24, 2010
We need to send out about 10.000 letters each month. They will be sent via postal services so I have to print them out with a new label/address on each letter. The envelope does have a window so the letter will be printed with the address.
All addresses will be found in a MSSQL database. I know how to make a SQL connection. I really need some input on how I would start doing this. The letter will be a twosided letter with the address in the upper right corner. How can I make a connection so that it loops trough the database for address and adds one by one. It should also add a new letter/page for each address found in the database.
View 1 Replies
Jan 29, 2011
How can i create dbml file for MS Access or suggest me any other method so that i can use LINQ with MS Access database.
View 4 Replies
Mar 17, 2010
I use the following string format to navigate between webpages:
String.Format(Eval("Hyper") + "?BUSINESSSTREAM={0}&Dealer={1}&LeadID={2}&Companyid={3}&SalesPerson={4}", Eval("BusinessStream"), Eval("Dealer"),Eval("leadId"),Eval("CompanyID"),Eval("SalesPerson"))
However the companyid is a text string and the company may have an "&" in it which I know will truncate the string. I have seen that this can be overcome by using "UrlEncode" [URL] However I cant solve the syntax.
View 10 Replies
Mar 27, 2011
I'm trying to import a few hundreds of data to a SQL server database table from Excell Spreedsheet. In the taable, I created Id as key that is identity. How can I solve identity when I import excel data to the database table.
View 3 Replies
Sep 8, 2010
I recognized that based on a context in which I want to use some parameters, there are at least 4 kinds of encoding that are necessary to avoid corrupted code being executed :
Javascript encoding when constructing a javascript code, e.g.
var a = "what's up ?"
var b = "alert('" + a + "');"
eval(b); // or anything else that executes b as code
[Code]....
View 3 Replies
Jan 16, 2011
I can successfully run a sample report on the local computer. DataSource and Report are valid it renders perfect.
But when i move my DataSource and Report to Remote server which is hosted by a company, then i always receive following error!. It is really disgusting.
An error occurred during client rendering.
An error has occurred during report processing.
Cannot create a connection to data source 'DataSource1'.
For more information about this error navigate to the report server on the local server machine, or enable remote errors
View 7 Replies
Jan 21, 2010
I dont know my server name, username or password and what do i put in the name section??
I am trying to create it for a data entry page.
View 2 Replies
Jun 22, 2010
I want to be able to create methods to do stuff like opening the connection to the database.Right now if I want to do that I have to put all the code to open the connection with the database in every class.What I did is create a new class called methods, this class is in the App_code folder.I have researched but don't understand how methods are created and how to call them. If someone can give me an example regarding a database connection method, I might be able to really understand how a method works. Basically, this is the code I have to use everytime I want to open a connection to the database:
string connectionString = ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString;
View 7 Replies
Mar 8, 2011
I am developing a web application which will deal with online examination. The requirement is:
There can be n-number of sections in an exam and admin users should be able to create questions/answers and add to an exam. The questions should be displayed for a certain amount of time in the browser with meclock and it should move to next question automatically. User should not be allowed to open any other instance of the browser or login from another IP if the exam is in progress.
I am seeking community vote of how would someone design the application to meet all these criterias? What patterns should be used? What components to reduce the development time etc..My technology stack is C#, ASP.NET MVC or ASP.NET with SQL Server.
View 3 Replies
Jul 15, 2010
I have a toolkit tabbed container with an update panel in the bottom of each of the tabbed container's content template. There is also a radio button list an, a text box and a button. The user chooses the search criteria with the radio button list. They then enter the search text in the text box and hit the search button.
The update panel is then going to display the appropriate grid view and results, depending on what radio button was chosen. The logic to check the radio buttons is in the click event of the search button. I currently have one of the grid views and set it's visible property to true in the logic that checks to see which of the radio buttons was selected. My plan so far is to continue adding the other gridviews and doing this the same way with them. This will toggle the correct Grid View on.
I'm wondering if there is a better way of dealing with the Grid Views. There will be one of three to be displayed with in this update panel. They will have different result sets from different tables. Is my approach for turning them off and on with the visible property a bad idea? Should I be doing all of the ODS and grid view stuff programmatically? Is there a better way of doing this?
View 2 Replies
Sep 6, 2010
How to create a connection string using Visual Studio 2010?
View 2 Replies
Aug 5, 2010
Is it possible to insert a connection string into a web.config file if it isnt there?Would this work?The connection string is for a APS.NET user login and create account database.
View 3 Replies
Feb 2, 2010
I have a problem.when i create a new web site and browse it with IE8 ,there is error(Internet Explorer cannot display the webpage) and now i am working with VS2008 and IE8.but i also have an older version of VS(VS2005) on the same computer.when i created a new web page with 2005 ,there is no problem and everything is ok. what is the problem with VS2008??i uninstalled it and reinstalled.but there is same error.i tried VS2008 on the another computer and i had no problem.
View 2 Replies