我試着寫在C#一個簡單的應用程序,將查詢提供一個數據庫,以位於https://newswire.theunderminejournal.com/從C#控制檯應用程序查詢網站數據庫
公衆他們給位於https://newswire.theunderminejournal.com/sample2.php
爲例據我所知,我試圖連接的服務器是「newswire.theunderminejournal.com」,數據庫是「報攤」。
這給我的字符串:
string connection_str ="Server=newsstand.theunderminejournal.com;Database=newsstand";
我的代碼如下所示:
xData = "Unable to connect to database.";
string server = "'newswire.theunderminejournal.com'";
//string server = "45.75.164.122";
string database = "'newsstand'";
string connection_str = string.Format("Server={0};Database={1};", server, database);
Console.WriteLine(connection_str);
SqlConnection connection = new SqlConnection(connection_str);
try
{
connection.Open();
xData = "Connection established!";
}
catch(Exception e)
{
xData = e.Message;
}
connection.Close();
connection.Dispose();
這僅導致的錯誤消息:
"A network-related or instance-specific error occured while not establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
我ping通服務器,得到一個IP地址在45.79.164.122,並沒有問題,所有ping它。
有什麼明顯的我在這裏失蹤?我是C#的全新人物,所以如果有另一種/更好的方式,我會很感激!
謝謝。
難道沒有連接到數據庫所需的用戶名和密碼? – KMoussa
確保您可以ping通它,但要打開連接,您是否沒有登錄憑據? – Jay
哎呀,對不起,不需要用戶\ pass。該人明確表示不以用戶\ pass登錄。 – Zulukas