このコードを読む必要がありますpath from app.Settings
が、今はそこに価値があります。このプロジェクトを.exe
ファイルとしてリリースし、インストールが成功した後に別のコンピューターにインストールしようとすると、実行するとエラーがスローされますsystem.IO.directorynotfound
.
私はそれが次のように見えると思いました:
private static string _ConnectionString;
public static string ConnectionString {
get {
if (_ConnectionString == null) _ConnectionString = FunctionToDynamicallyCreateConnectionstring();
return _ConnectionString;
}
}
private static string FunctionToDynamicallyCreateConnectionstring() {
string path = Properties.Settings.Default.swPath;
if (path != null) {
StreamReader sr = new StreamReader(File.Open(path, FileMode.Open));
SqlConnectionStringBuilder cb = new SqlConnectionStringBuilder();
cb.DataSource = DecodeFrom64(sr.ReadLine());
cb.InitialCatalog = DecodeFrom64(sr.ReadLine());
cb.UserID = DecodeFrom64(sr.ReadLine());
cb.Password = DecodeFrom64(sr.ReadLine());
}
return cb.ToString();
}
しかし、それは次のエラーを出しますThe name 'cb' does not exist in the current context
: しかし、それを改善する方法がわからないので、特定のコンピューターでパスが見つからない場合、プログラムは通常、正しいパスを設定するまで続行します。
皆さん、お時間とご回答ありがとうございます。