Usage of database connection words in web.config

zhaozj2021-02-12  135

In the setting of the web program in ASP.NET, we must use Web.config to store database connection words. In fact, this is a good practice, because you can save us a lot of troubles can also help us avoid unnecessary misplaced It is a lot of cases. I will do this. It records this information through XML. Specific is

....

This tag is recorded. Here, please see an example of Oracle as follows:

, in your application, you only Write, you can, as follows:

String conn = configurationSettings.appsettings ["OracleConnectionString"]; OLEDBCONNECTION MyConnection = New OLEDBCONNECTION (CONN);

Very easy? Don't you need to enter the same connection word every time, don't remember those hate information, just need a good name. Well, I will give other connection words:

Mysql connection word: connectionString = "Data Source = localhost;" "Database = mysqldatabase;" "user ID = myusername;" "password = mypassword;" "Command logging = false"; OLE DB: IBM AS / 400 OLE DB

'VB.NETDim oOleDbConnection As OleDb.OleDbConnectionDim sConnString As String = _ "Provider = IBMDA400.DataSource.1;" & _ "Data source = myAS400DbName;" & _ "User Id = myUsername;" & _ "Password = myPassword" oOleDbConnection = New OLEDB.OLDBConnection (Sconnstring) Ooledbconnection.Open () Jet OLE DB

'Vb.netdim ooledbconnection as oledb.oledbconnectiondim sconnstring as string = _ "provider = microsoft.jet.Oledb.4.0;" & _ "data source = c: /mypath/myjet.mdb;" & _ "user ID = admin; "& _" Password = " 'VB.NETDim oOleDbConnection = New OleDb.OleDbConnection (sConnString) oOleDbConnection.Open () Oracle OLE DB of oOleDbConnection As OleDb.OleDbConnectionDim sConnString As String = _" Provider = OraOLEDB.Oracle; "& _" Data Source = Myoracledb; "& _" User ID = myusername; "& _" Password = mypassword "ooledbconnection = new oledb.oledbconnection (sconnstring) oledbconnection.open () SQL Server Ole DB

'VB.NETDim oOleDbConnection As OleDb.OleDbConnectionDim sConnString As String = _ "Provider = sqloledb;" & _ "Data Source = myServerName;" & _ "Initial Catalog = myDatabaseName;" & _ "User Id = myUsername;" & _ " Password = mypassword "ooledbconnection = new oledb.oledbconnection (sconnstring) oledbconnection.open () Sybase ASE OLE DB

'VB.NETDim oOleDbConnection As OleDb.OleDbConnectionDim sConnString As String = _ "Provider = Sybase ASE OLE DB Provider;" & _ "Data Source = MyDataSourceName;" & _ "Server Name = MyServerName;" & _ "Database = MyDatabaseName;" & _ "User ID = myusername;" & _ "Password = mypassword" ooledbconnection = new oledb.oledbconnection (sconnstring) oledbconnection.open () SQL Server is in system.data.sqlclient

SqlConnection oSQLConn = new SqlConnection (); oSQLConn.ConnectionString = "Data Source = (local);" "Initial Catalog = mySQLServerDBName;" "Integrated Security = SSPI"; oSQLConn.Open (); herein are used VB.NET Written, I hope to help friends with VB written asp.net.

转载请注明原文地址:https://www.9cbs.com/read-7503.html

New Post(0)