conecting後,我已經instaled SQL Server上的MI PC,然後創建數據庫和表:缺少的表由C#
Create database DatabaseX;
CREATE TABLE MainTable
(
Product varchar(255),
ProductDescription varchar(255),
ProductPrce int
);
,並添加森達信息給它,當我在SQL Managmend工作室我的工作通過Windows驗證登錄。因此,我創建WPF瞬移到這個數據庫:
try
{
SqlConnection myConnection = new SqlConnection("user id=" + DatabaseUsernameTextBox.Text + ";" +
"password=" + DatabasePasswordTextBox.Text + ";server=" + DatabaseServerTextBox.Text + ";" +
"Trusted_Connection=" + DatabaseTrustedConectionComboBox.SelectedItem + ";" +
"database=" + DatabaseNameTextBox.Text + "; " +
"connection timeout=" + DatabaseConectionTimeouTextBox.Text + "");
myConnection.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
連接如通過:本地主機,DatabaseX的作品,沒有什麼異常,但....不管我粘貼爲用戶ID和密碼,它總是瞬移,不exackly如何?所以接通,但當我嘗試:
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select * from MainTable;", myConnection);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
Console.WriteLine(myReader["ProductName"].ToString());
//Console.WriteLine(myReader["Column2"].ToString());
}
有一個例外,「無效的對象名'MainTable'。」任何想法爲什麼?
這就是我的想法也是如此。在Management Studio連接上下文仍是主分貝。 –