2012-04-19 11 views
1
SqlConnection con = new SqlConnection(@"Server=.\SQLEXPRESS;AttachDbFilename='C:\HashTags.mdf';Integrated Security=True;User Instance=True"); 

con.Open(); 
String queryStr = "SELECT name FROM ttable WHERE name LIKE '*%'"; 
SqlCommand com = new SqlCommand(queryStr, con); 
SqlDataReader sdr = com.ExecuteReader(); 

while (sdr.Read()) 
{ 
    this.trendingBx.Text = sdr.GetValue(0).ToString(); 
} 

sdr.Close(); 

誰を教えてもらえ:C#のデータベースエラーが

すでに&チェックして「指定されたファイルを開くことができない、またはそれがUNC共有に配置されている」と仮定すると

A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

答えて

1

データベースはまだ接続されていませんか?それはあなたが使用する必要があります:

Data Source=.\SQLEXPRESS;Database=your database name;Integrated Security=SSPI 
+0

私は自分のコードにどのように追加しますか?角かっこの中だけで? – user1300788

+0

SqlConnection con =新しいSqlConnection(@ "サーバー=。\ SQLEXPRESS;データベース=ハッシュタグ;統合セキュリティ= sspi"); – richk

0

AttachDbFilename='C:\HashTags.mdf' 

は次のようになります:.mdf場所に存在しない、私はあなたが接続文字列に引用符を有する必要はないと思います

AttachDbFilename=C:\HashTags.mdf (no single quotes) 

これはIMOで動作するはずです。

0

あなたは使用する必要があります。

Integrated Security=SSPI 

ない

Integrated Security=True 

を接続文字列に。

関連する問題