string DBServer = BCPCommon.ReadINI("DB", "DBServer", "", INIPath + "\\BCP.ini");//调用ReadINI方法/*ReadINI方法*/
public static string ReadINI(string section, string key, string def, string filename)
        {
            StringBuilder temp = new StringBuilder(1024);            try
            {
                GetPrivateProfileString(section, key, def, temp, 1024, filename);//调用GetPrivateProfileString方法
                return temp.ToString();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                temp = null;
            }
        }
/*GetPrivateProfileString方法*/
[DllImport("kernel32")]
        private static extern int GetPrivateProfileString(
        string lpAppName,
        string lpKeyName,
        string lpDefault,
        StringBuilder lpReturnedString,
        int nSize,
        string lpFileName
        );
/*.ini文件*/
[DB]
DBServer=203.163.38.158
DBName=Northwind
UserID=sa
Password=sa[Path]
BCPOutPath=c:\BCPDemo
BCPInPath=c:\BCPDemo
LogPath=c:\BCPDemo[Flag]
Run=O[Timer]
Interval=100

解决方案 »

  1.   

    BCP.ini是关于同目录下面文本文件里面数据的描述吗猜测是读取文本中数据的,如果是,那个访问sql差不多
      

  2.   

    就是调用API来读取了个配置文件里的数据库链接字串 
      

  3.   

    自从有了XML后 现在都用xml了吧
      

  4.   

    kernel32是不是这个系统文件有自动解析INI文件的功能?对吗?
      

  5.   

    调用 Win32 API 函数 GetPrivateProfileString 读取ini文件...古老的方法...过时很久了...
      

  6.   

    这个问题还没人回答我呢
    kernel32是不是这个系统文件有自动解析INI文件的功能?对吗?
      

  7.   

    一点也不可靠...会有编码问题...不支持UTF-8...
      

  8.   

    kernel32是不是这个系统文件有自动解析INI文件的功能?对吗?
    ---------------
    不对...kernel32只是提供了这个API函数...
      

  9.   

    我的意思是说是不是GetPrivateProfileString这个函数有自动解析INI文件的功能?
    如果还不是,那他是如何解析的?
    还有INI文件必须要是我上面写的那种格式吧。
    是不是可以重写GetPrivateProfileString方法来支持更多的INI格式?
      

  10.   

    ini只有一种格式...[section]
    key=value
    ....你应该去看看相关的文档...不过也没什么必要了...除了兼容旧的系统ini已经没有应用的价值...