![]() ![]() Additionally, you can secure the connection string using encryption. An advantage to storing connection string information in the Web.config file is that you can easily change the server name, database, or authentication information without editing individual Web pages. Any data source control on any page in the application can reference this connection string entry. In this example, the name and provider are both supplied. ![]() Within the Element element, you can create a child element named and place your connection strings there, as shown in this example: It is good practice to place connection strings in the Web.config file. As with the provider, you can indicate the connection string within the Web.config file or as a property of an individual data source control on a page. You can store a connection string in the Web.config file and reference the configuration entry in a data source control.ĭepending on the provider, a connection string usually supplies the server or location of the database server, the particular database to use, and authentication information. Connection StringsĪ connection string provides the information that a provider needs to communicate with a particular database. You can specify the provider in Web.config file as part of a connection string, or as a property of an individual data source control on a page. NET Framework Data Provider for Oracle in the namespace. NET Framework Data Provider for ODBC in the namespace. NET Framework Data Provider for OLE DB in the namespace. This provider is the default for the SqlDataSource control if you are connecting to a SQL Server database using the SqlDataSource control, you do not need to explicitly specify a provider. NET Framework Data Provider for SQL Server in the namespace. For example, one provider might be able to communicate with a SQL Server database, and another provider might be able to communicate with an Oracle database. For more information, see "Connection Strings" later in this topic.Īn ADO.NET provider is a class that can communicate with a specific type of database or data store. It also helps you secure the connection string information using access control lists (ACLs) and encryption. ![]() Storing connection information in the Web.config file allows you to reuse the information with multiple data control instances. You can specify provider and connection information as individual properties of the SqlDataSource control, or you can define provider and connection string information centrally in the Web application's Web.config file. The LinqDataSource control requires the name of the class that represents the database and the name of the class that represents the table from which you will access data. The SqlDataSource control requires a connection string that includes the information that the provider needs to open a specific database and one or more SQL commands to query or modify data. For example, the ObjectDataSource control requires the type of the middle-tier business object and one or more methods to query or modify data. The default is the provider, which connects to a Microsoft SQL Server database.Īdd the data source control to the page and set its properties for data access. ![]() A provider is a class that communicates with a specific type of database. If you use the SqlDataSource control, determine what provider you need. For more information, see How to: Create LINQ to SQL Classes in a Web Project. You connect the LinqDataSource control to these classes. If you use the LinqDataSource control, create classes to represent the database and tables. The SqlDataSource control enables you to supply a connection to a data source and SQL statements to retrieve and modify data. The ObjectDataSource control works with a middle-tier business object to retrieve and modify data. For example, the LinqDataSource control enables you to use LINQ syntax in markup code to access data from a variety of data sources. To connect to a database using a data source control, you do the following:ĭetermine the type of data source control you need. Using Data Source Controls in an ASP.NET Web Page Alternatively, you can write code to perform data access yourself using ADO.NET classes or LINQ queries. A simple way is to use data source controls, which allow you to encapsulate data access in a control that you can configure with connection and query information. ASP.NET gives you flexibility in how you connect to databases. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |