Author: water and smoke
The configuration of the data source connection string is a great learning. Here I can only talk about how to connect to it. I don't understand performance security and so on.
String connection modes of various data sources can be easily found at http://www.connectionstrings.com.
The connection to the data source is difficult to remember because of the many parameters and the keyword. Therefore, it is difficult to assemble this string. What we need is a visual wizard form to simplify the configuration process. Even if there is no net, this visual form already exists in the window, that is, the "Data Source (ODBC)" in the control panel or management tool. When adding a DSN, guides us how to do this. What we prefer is the "Data Link attribute" dialog box.
Sometimes it is strange that since this wizard form is so common and important, why is it not provided by net?
In net2005, under the X: \ Program Files \ Microsoft Visual Studio 8 \ common7 \ ide directory, We can find two files, net real class files, Microsoft. data. connectionui. DLL and Microsoft. data. connectionui. dialog. DLL, that is to say, it is still dedicated to the IDE and does not want to be used for framework2.0. Framework2.0,ProgramThe configuration file has a section on connectionstring. design. DLL system. data. in the design namespace, there is already a connectionstring class. data. DLL, an additional system. data. under the common namespace, dbconnection, dbconnectionoptions, and dbconnectionstring are connected. For the convenience of string assembly, there is also a dbconnectionstringbuilder class. The classes mentioned above are inherited when specific connection methods are used. It is estimated that there should be a visual wizard form for data source connection in the next version. No?
In fact, it is not difficult to make a visual wizard form for data source connection. Of course, it is only the effect. For net, it is not orthodox, so it is not streaming. Net projects are very favored, so when we try to repackage the underlying functions, We have to shake our head and sigh. Here, I want to say that it is inseparable from oledb32, or even ADODB. When I used to do VB, I used to get used to ADODB and sometimes used Dao. Now, when I reference the namespace, I saw ADODB in the class library instead of COM. Take a closer look. The file is X: \ Program Files \ Microsoft. NET \ primary InterOP assemblies \ ADODB. dll. Oh, it turns out to be InterOP. ADODB. dll.
The following figure shows the effect of a visual wizard form for data source connection. Microsoft ActiveX Data Objects 2.8 Library (ADODB) and Microsoft ole db service component 1.0 Type Library (the "Data Link property" form) are used ). For different versions, I use Createobject for indirect reference instead of direct reference.
There are two scenarios for processing the connection string. One is to create a new connection string and the other is to edit an existing connection string. Processing ProcessCodeRefer to the following:
New connection string (http://support.microsoft.com/default.aspx? SCID = KB; en-US; 310083)
Dim strconn as string
Dim objdatalinks as datalinks
Dim bolstatus as Boolean
Dim CNN as ADODB. Connection
Set CNN = new ADODB. connecton
Set objdatalinks = new datalinks
'Get user' s first settings for the connection.
Strconn = objdatalink. promptnew
Msgbox (strconn)
'Assign the settings to the connection object.
CNN. connectionstring = strconn
'Display Connection Properties for editing.
Bolstatus = objdatalinks. promptedit (CNN)
If bolstatus = false then
Msgbox ("changes were canceled ")
Else
Msgbox ("new settings are:" & CNN. connectionstring)
End if
Set objdatalinks = nothing
Set CNN = nothing
Edit the connection string (http://windowssdk.msdn.microsoft.com/library/default.asp? Url =/library/en-US/oledb/htm/oledbi1_celocator_promptedit.asp)
Dim bolstatus as Boolean
Dim CNN as ADODB. Connection
Dim objdatalinks as datalinks
Set CNN = new ADODB. connecton
Set objdatalinks = new datalinks
CNN. provider = "Microsoft. Jet. oledb.4.0"
CNN. properties ("Data Source") = "northwind. mdb"
Bolstatus = objdatalinks. promptedit (CNN)
If bolstatus = false then
Msgbox ("User pressed cancel button ")
End if
Msgbox (CNN. connectionstring)
Set objdatalinks = nothing
Set CNN = nothing
The next section provides the VB. NET code.