错误消息';此操作系统不支持指定的区域设置';

本文关键字:区域 设置 操作系统 消息 错误 不支持 | 更新日期: 2023-09-27 18:20:05

我使用以下方法创建数据库文件。

public bool CreateDatabaseFile()
{
    try
    {
        Stream file = File.Create(DBPath);
        file.Close();
        return true;
    }
    catch (Exception)
    {
        return false;
    }
}

但当我打电话给时

 public void CreateDatabaseStruct()
 {
     var queries = new List<string>
     {
         "create table contacts ('"name'" nvarchar,'"emails'" nvarchar);",
         "create table errors ('"code'" int, message nvarchar);"
     };
     foreach (string query in queries)
     {
         var con = new SqlCeConnection(connectionString);
         con.Open();
         var cmd = con.CreateCommand();
         cmd.CommandText = query;
         cmd.ExecuteNonQuery();
         con.Close();
     }
 }

它返回

此操作系统[LCD-1]不支持指定的区域设置。

我该如何解决这个问题?

更新

连接字符串:

 public static readonly string DBPath = "db.sdf";
 public static readonly string connectionString = String.Format("Data Source={0}; Password=...", DBPath);

错误消息';此操作系统不支持指定的区域设置';

解决方案是使用SqlCeEngine.CreateDatabase()创建它。

您是否通过LCD=####在连接字符串中指定区域设置ID(其中####是支持的4位LCID编号)?如果是,你确定你的操作系统支持它吗?

如果没有,也许您的操作系统设置为不同的区域性,而数据库不支持该区域性。

请发布您的连接字符串,并提供有关您正在使用的O/S的更多信息(如@MusiGenesis所述)。