2012-02-09 17 views
0

I'veは次れたconnectionStringを得ました。 mdfファイルは、Datenbankというフォルダにあります。これは、接続文字列に入力したフォルダにあります。のConnectionString MDFファイル

..\\と思われます。 誰かがその問題の解決策を持っていますか?

+0

あなたが見ているエラーは何ですか? –

+0

私は信じて| DataDirectory |プロジェクトフォルダの下にある "App_Data"フォルダを指します。 –

+2

タイトルに「C#」などのプレフィックスを付けないでください。それがタグのためのものです。 –

答えて

2

次のコードを使用してdirを計算できます。

//these two lines get the executable's directory 
Uri u = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase); 
DirectoryInfo d = new DirectoryInfo(Path.GetDirectoryName(u.LocalPath)); 

//this goes up two directories and combines that directory with the rest 
//of the path to the file 
string path = Path.Combine(d.Parent.Parent.FullName, @"Datenbank\FarmersCalc.mdf;"); 
Console.WriteLine(path); 
+0

パスにGetDirectoryNameの定義が含まれていません... – user896692

+0

どのバージョンのcsharpを使用していますか?明らかにこれが動作するには、 'System.IO'と' System.Reflection'名前空間を含める必要があります。私はそれが問題だとは思っていません。それをそこに置くだけです。 –

関連する問題