青
青云
Unregistered / Unconfirmed
GUEST, unregistred user!
oracle的服务名文件是一个简单的文本,一般目录是:d:/oracle/product/10.2.0/db_1/NETWORK/ADMIN/tnsnames.ora文件内容是:# tnsnames.ora Network Configuration File: G:/oracle/product/10.2.0/db_1/NETWORK/ADMIN/tnsnames.ora# Generated by Oracle configuration tools.STP= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dzcnb)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dzcdb) ) )HOLLEYWMS = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = dzcnb)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = dzcdb) ) )目的是把 STP 和HOLLEYWMS这两个服务名取出来放到Tcombobox里;找了一段java 代码,有兴趣的可以一起翻译成delphi,Date: 19 Feb 2004 13:16:27 -0800Here is a function to parse the TNSNames.ora file to get a list of oracle databases configured on a machine... It's nothing fancy, but I know that I needed it, so, hopefully it will be helpful to someone else. public static string[] GetDatabases() { string output = ""; string fileLine; Stack parens = new Stack(); // open tnsnames.ora StreamReader sr; try { sr = new StreamReader(@"C:/oracle/ora92/network/ADMIN/TNSNAMES.ORA"); } catch (System.IO.FileNotFoundException ex) { throw ex; } // Read the first line of the file fileLine = sr.ReadLine(); // loop through, reading each line of the file while ( fileLine != null) { // if the first non whitespace character is a #, ignore the line // and go to the next line in the file if (fileLine.Length>0 && fileLine.Trim().Substring(0,1) != "#") { // Read through the input line character by character char lineChar; for (int i = 0; i<fileLine.Length; i++) { lineChar = fileLine; if (lineChar == '(') { // if the char is a ( push it onto the stack parens.Push(lineChar); } else if (lineChar == ')') { // if the char is a ), pop the stack parens.Pop(); } else { // if there is nothing in the stack, add the character to the ouput if (parens.Count==0) { output += lineChar; } } } } // Read the next line of the file fileLine = sr.ReadLine(); } // Close the stream reader sr.Close(); // Split the output string into a string[] string [] split = output.Split('='); // trim each string in the array for (int i=0; i<split.Length; i++) { split = split.Trim(); } Array.Sort(split); return split; }