[英]ASP.NET application is reachable as localhost but not 127.0.0.1
[英]SQL Server not reachable from ASP.NET application
我有一個ASP.NET頁,該頁的格式很小,可以處理其課程的注冊。
顯然,此表單中的數據必須插入數據庫中。
我的問題在於與數據庫服務器的實際連接,出於測試目的,我將其連接到本地PC上。
我可以通過SQL Server Management Studio很好地連接到服務器,但是,當我嘗試從Web應用程序進行連接(純粹將其上傳到免費主機進行測試)時,卻出現以下錯誤:
建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱正確,並且已將SQL Server配置為允許遠程連接。 (提供者:TCP提供程序,錯誤:0-嘗試以其訪問權限禁止的方式訪問套接字。)
經過廣泛的Google搜索並在我的web.config
文件中重寫了連接字符串之后,我仍然找不到確切的問題所在。
我知道我正在使用的DNS可以正常工作,因為我的一個朋友幾天前已經通過其自己的SQL Server Management Studio連接進行了測試。
這是我的web.config
:(很明顯,空白處的密碼是空白的)
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"/>
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<connectionStrings>
<add name="SQLCS"
providerName="System.Data.SqlClient"
connectionString="Server=ydekempe.ddns.net,5555\Cocktails;Database=Website;Integrated Security=False;User ID=WebUser;Password=********;"/>
</connectionStrings>
</configuration>
只是為了完整地為您提供可能需要的一切,以下是實際連接的代碼:
protected void Inschrijven(object sender, EventArgs e)
{
int uid = 0;
string conStr = ConfigurationManager.ConnectionStrings["SQLCS"].ConnectionString;
try
{
using (SqlConnection conn = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand("Inschrijven", conn))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@naam", txtNaam.Text.Trim());
cmd.Parameters.AddWithValue("@voornaam", txtVoorNaam.Text.Trim());
cmd.Parameters.AddWithValue("@Email", txtEmail.Text.Trim());
cmd.Connection = conn;
conn.Open();
uid = Convert.ToInt32(cmd.ExecuteScalar());
conn.Close();
}
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
string msg = "";
switch (uid)
{
case 0:
msg = "Er ging iets mis.\\nProbeer later opnieuw";
break;
case -1:
msg = "Dit e-mail adres is al in gebruik.";
break;
default:
msg = "Inschrijving verwerkt.";
break;
}
ClientScript.RegisterStartupScript(GetType(), "Boodschap", "Boodschap: '" + msg + "');", true);
}
PS:實際的連接信息是IP:ydekempe.ddns.net和端口:5555以防萬一您想知道。
數據庫服務器是您的本地服務器,Web服務器托管在哪里? 您提到這是一個免費主機,我想它不在您的本地計算機上。 確保可以從托管Web應用程序的任何位置訪問您的計算機。 例如,如果它在AWS中,則必須驗證入站和出站規則。
原來,這是Web主機阻止傳出端口。
來自SmarterASP的技術支持的回復 :
尊敬的客戶,
抱歉,由於性能原因,我們不允許客戶連接到遠程數據庫服務器。 我們建議您僅備份數據庫並將其還原到我們的服務器以測試您的應用程序。 使用這種方法,您將看到更快的性能和可靠性。
但是,如果必須連接到遠程數據庫服務器,請考慮升級到我們的高級計划或Semi Dedi計划。 升級到這些托管計划后,可以在控制面板->安全管理器->傳出端口管理器中啟用所需的任何端口。
不用擔心,我們為所有計划提供60天全額退款。
謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.