DataSource Controls :: Vb.net Database Connection - Try/catch Or Using?
Jun 11, 2010
I'm trying to weigh up which is the better most reliable database connection for use on a vb.net/ms sql site. I've previously experienced problems catching and closing db connections with the using statement if an error occurs, but do like the fact it doesn't need to use any global variables. Both examples use a general Database class file which opens and closes a connection.my current examples are: TRY CATCH EXAMPLE:
[Code]....
[Code]....
View 1 Replies
Similar Messages:
Feb 11, 2011
Is there a way to catch a database exception and then redirect to an error page? I have a data access class that I use to make a sql connection and then functions that call it to execute my SQL commands. My problem is that if my database is not available I cannot catch that error. Here is the code I am using in my class:
Protected Function GetConnection() As SqlConnection
Dim ret_conn As SqlConnection
ret_conn = New SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings("EUCNET00617").ToString())
ret_conn.Open()
GetConnection = ret_conn
End Function
View 3 Replies
Mar 25, 2011
I have developed Dynamic Data application for DB administration. I'd like to show thrown exception message (when connection to db is closed) in UI friendly manner. I cant figure out where to catch this exception.
Tried EntityDataSource events in List PageTemplate - no success.
View 1 Replies
Feb 7, 2010
Here is the code copied from [URL] In asp.net code behind, I use try-catch try to catch any error but never catch it. In SQL database, if I rename Employees to Employeesx or change column DepartmentID to DepartmentIDx, record will not be deleted (it is right) without any error (it is wrong, suppose catch an error).
CREATE PROCEDURE DeleteDepartment
(
@DepartmentID int
)
AS
BEGIN TRANSACTION
DELETE FROM Employees
WHERE DepartmentID = @DepartmentID
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error', 16, 1)
RETURN
END
DELETE FROM Departments
WHERE DepartmentID = @DepartmentID
IF @@ERROR <> 0
BEGIN
ROLLBACK
RAISERROR ('Error', 16, 1)
RETURN
END
OMMIT
View 2 Replies
Apr 1, 2010
I'm having a problem, which I haven't had with other projects, in setting up membership. I have set up a aspnetdb database using the asp.net confirguration tool. The database is in the app data folder and I can set up users and roles etc from the web site administration tool. However, trying to log in within the application, using the login control I get "Login attempt was not successful".
I have noted the following :-
1. On the home page of the Web site administration tool the application:/ shows no application where as normally it would show the name of the application.
2. Clicking the AspNetSqlProvider test button, I get the error "could not establish a connection to the database"
3. Although various lines have been added to the web config file, no connection string has been created to the aspnetdb file in the app data folder.
4. If you right click on the aspnetdb file within the solution explorer, there is an option of "include in project". Selecting this doesn't however solve the problem.
View 2 Replies
Aug 16, 2010
I try to connect my database for so long so i wrote two type of codes. Let's discuse first on.
I have database called PhoneDirectory.
It have only one table named Residents.
I have button wiht ID="Button1".
I want when i click this button to see all of my residents.
I want to see the result in DetailsView and to be able to edin, delete and add new resident.
First try with SqlDataSource so i wrote this:
<asp:SqlDataSource ID="Resident Details" runat="server" ProviderName="System.Data.SqlClient" ConnectionStrings="<%$ ConnectionStrings:ThisIsTheConnection%>"
View 57 Replies
Feb 4, 2010
My website is working but when I host it up, the connection are all screw up. Is it because my connectionString are all linked via SqlDatasource and is for local files only? Whats the coding that I need to put in so that my site will connect to the database via accessing the web.config or server?
View 11 Replies
May 4, 2010
I am designing a web application and have separate layers for UI, BAL, DAL and DB, while using custom business objects and collections. The app will be used by over 10,000 + registered used and it becoming more complex as I add new functionality such as inline editing and batch processing of collections with transactions ... which has me up late at night trying to design the best approach for this ...In some UI web forms, I bind say 3 controls to 3 different collections. The UI calls the BAL classes for the required collections, then binds the collection returned. So for each collection I want, a db connection is opened and closed. As I understand database connectivity adds overhead so Is there anyway I can design this so 1 database connection is created for a unit of work in a 3-tier or n-tier architecture?
View 7 Replies
Sep 10, 2010
How do we convert, the following code to query a SQL database with ASP using a DSN-less connection
[Code]....
View 2 Replies
Mar 23, 2010
Is it mandatory to close database connection in enterprise library 4.1?
View 1 Replies
Jun 14, 2010
am writing a series of WSS/MOSS webparts amongst which one will need to detect the current SQL Server database connection, prompt the user to setup a new connectionstring, and fire appropriate stored procedures to create a new database if needed. The user needs to be presented a textbox or label control with the current database connection. I've never had to detect current database connection, what methods do I call for this? If the desirable connection is not present, the web application needs to prompt the user to make a new database. The user really won't make the database, they simply need to click the command button which will fire the stored procedure to create the database.
View 1 Replies
Jun 5, 2010
First off, I am just getting started with ASP.NET so I expect this is something that I am doing.
i am trying to make a connection to a MS SQL database on my local machine.
I have the following in web.config
[code]....
View 4 Replies
Jun 15, 2010
I'm using an ODBC connection to connect a SQL 2005 database to my ASP.NET app in Visual Web Developer Express. I'm finding that the expected functionality that tutorials review does not work for ODBC connected databases the same way as it does for SQL databases created in the Web Developer. For example, I can't use stored procedures because the option to create one is disabled in the Web Developer, and if I create the stored procedure in SQL Server Management Studio Express, it doesn't show up in Web Developer because Web Developer only finds the system stored procedures, not the user-defined ones. I've seen other cases as well where database management options in Web Developer don't work with ODBC databases.
Am I missing something in my setup, or is there an inherent limitation with ODBC connected databases? Or, is this a limitation with using the Express versions of these development tools?
View 2 Replies
Dec 2, 2010
Catch IP from which receiving a connection (With proxy)?
View 4 Replies
Apr 7, 2010
In my DAL i have more than 100 methods/Function, each and every method am opening the sqlconnection and closing the connection, this is taking too much of time to establish the connection at every time. So what i expect is one common class will create the SqlConnection that will check if the connection is Broken or Closed then create the connection again else return the connection, how to do this(Also i would like to apply ConnectionPooling).
View 7 Replies
Jul 23, 2010
I am using VS2008 and oracle 10g ODP.Net. The oracle database that I used in the connection is working and tested it using sql plus.The connection string when used in a GriDView works perfectly. Now when I created a new listview control with the same connection it gives an error.Database schema could not be retrieved for this connection. Please make sure connection settings are correct and the database is online
Object reference not set to an instance of an object at VSDataObjectSupport (478,6)
View 2 Replies
Feb 10, 2012
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$appSettings:ConnString%>"Â SelectCommand="sql query ............."
This is in design and with the above I have
 SqlDataSource1.SelectCommand = "sql query ............. " in code behind
but if i have the connection in code behind. How do I execute
SqlDataSource1.SelectCommand == "sql query ............. "
It without any reader or dataset...
View 1 Replies
May 23, 2010
How/Can I Set the try, catch statment to catch a specific Error. For example i am getting the following error:
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '='., [SqlException (0x80131904): Incorrect syntax near '='.]
Basicly The = is part of my SQL string which points to a table that currently doesent exist. I want something like catch ex as SqlException (0x80131904) or catch ex as SqlException = "0x80131904" or even catch ex as System.Data.SqlClient.SqlException = "Incorrect syntax near '='." I just want something so i can put "table doesnt exist" in the error message without having to use:
catch ex as System.Data.SqlClient.SqlException
As i have other code on my page that could result in a different type of sqlExeption.
View 4 Replies
Sep 27, 2010
I have a stored procedure that creates a dynamic query. Sometimes the query is not built because there are no elements in the dynamic query. When the aspx page loads the SqlDataSource throws an error that the query is malformed. How can I catch this error, and handle it with a default message, before it returns the error to the aspx page?
View 2 Replies
May 20, 2010
I have several web forms which use a GridView linked to a DataSource control which is defined at design time as follows:
<cc1:pgsqldatasource
id="dsStates"
runat="server"
connectionstring="<%$ ConnectionStrings:PgSqlConnection %>"
oldvaluesparameterformatstring="Original_{0}"
providername="<%$ ConnectionStrings:PgSqlConnection.ProviderName %>" >
</cc1:pgsqldatasource>
As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.
View 1 Replies
Nov 15, 2010
i am trying to create connection using OLEDB connection in my app. but i am not able to create the connection as in datasource i want to use Server.mappath, but cudn't find the right method to use it. i am trying to make connection with Access database file. following is code i have tried:
string path = Server.MapPath("~/uploadaccess/Production.mdb");
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb")&";";
and also
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path&";");
and tried this
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb"));
and this is the error i am getting:
Operator '&' cannot be applied to operands of type 'string' and 'string'
View 3 Replies
Feb 23, 2010
i have an asp page through which i want to access FTP server And retrieve data (only file properties )from there and get it in excel (or just display it on the browser)is there any way i can keep it simple and acess the data from the server ???
View 1 Replies
Mar 7, 2010
Connection Errors
[Code]....
View 5 Replies
Mar 11, 2010
I was just wondering what would be the best practice for sql connection in asp.net, when using a loop
[Code]....
or...
[Code]....
View 2 Replies
May 27, 2010
The attached code, the oledb part, is giving me a blank web page saying it cant connect on my local dev server. I have another app with the same code, in fact I copied it and changed the db names. The one I copied from works fine.
[Code]....
View 5 Replies