我正在使用ASP.NET Framework 4.5中的Web应用程序。 SQLSERVER数据库已连接到项目。一切都很好,我已经完成了这个项目。在发布项目之前,我将连接字符串更改为在线服务器数据库。该网站已成功发布。
要对应用程序进行一些小的更改,我将连接字符串更改回本地数据库。现在,当我运行应用程序时,我收到以下错误:
' /'中的服务器错误应用
找不到网络名称。
描述:在执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息: System.ComponentModel.Win32Exception:找不到网络名称
来源错误:
Line 49:
Line 50: DataTable dt = new DataTable();
Line 51: conn.Open(); // Throws Exception Here
Line 52: string query = "SELECT Event.StartDate, Event.title, Artist.[Stage Name] FROM Event INNER JOIN Artist ON Event.ArtistID=Artist.ID WHERE StartDate >= GETDATE() ORDER BY CONVERT(DateTime, StartDate,101) DESC";
Line 53: SqlDataAdapter da = new SqlDataAdapter(query, conn);
源文件: c:\ Users \ Junaid \ Desktop \ FAST \ PasoFino \ Artist Management \ ArtistManagementSystem \ ArtistManagementSystem \ Views \ Portal \ Dashboard.aspx.cs Line:51
堆栈追踪:
[Win32Exception (0x80004005): The network name cannot be found]
[SqlException (0x80131904): A network-related or instance-specific error occurred while 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)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +332
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +699
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +89
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +426
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +191
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +154
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +21
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +90
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +217
System.Data.SqlClient.SqlConnection.Open() +96
ArtistManagementSystem.Views.Portal.Dashboard.showUpComingEvents() in c:\Users\Junaid\Desktop\FAST\PasoFino\Artist Management\ArtistManagementSystem\ArtistManagementSystem\Views\Portal\Dashboard.aspx.cs:51
ArtistManagementSystem.Views.Portal.Dashboard.Page_Load(Object sender, EventArgs e) in c:\Users\Junaid\Desktop\FAST\PasoFino\Artist Management\ArtistManagementSystem\ArtistManagementSystem\Views\Portal\Dashboard.aspx.cs:20
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
这是我的Web.Config:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<sessionState mode="InProc" timeout="20"></sessionState>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="1048576"/>
<pages>
<controls>
<add assembly="TimePicker" namespace="MKB.TimePicker" tagPrefix="cc1"/>
<add tagPrefix="ajaxtoolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolKit"/>
</controls>
</pages>
<!--<authentication mode="Forms">
<forms loginUrl="Views/Login/Login.aspx" defaultUrl="Views/Portal/Dashboard.aspx">
<credentials passwordFormat="Clear">
<user name="junaid" password="fastian123"/>
</credentials>
</forms>
</authentication>
<authorization>
<deny users="?"/>
</authorization>-->
</system.web>
<connectionStrings>
<!--<add name="ArtistManagementSystemEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=REDDEVIL\SQLEXPRESS;initial catalog=ArtistManagementSystem;persist security info=True;user id=sa;password=fastian123;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
<add name="ArtistManagementSystemConnectionString" connectionString="Data Source=REDDEVIL/SQLEXPRESS;Initial Catalog=ArtistManagementSystem;Persist Security Info=True;User ID=sa;Password=fastian123;MultipleActiveResultSets=True;Application Name=EntityFramework"
providerName="System.Data.SqlClient" />-->
<add name="ArtistManagementSystem" connectionString="Data Source=REDDEVIL/SQLEXPRESS;Initial Catalog=ArtistManagementSystem;User ID=sa;Password=***********" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
这是我收到错误的地方:(Dashboard.aspx)
protected void showUpComingEvents()
{
//string myConnection = dbController.connectionString;
string myConnection = dbController.connectionString;
SqlConnection conn = new SqlConnection(myConnection);
DataTable dt = new DataTable();
conn.Open();
string query = "SELECT Event.StartDate, Event.title, Artist.[Stage Name] FROM Event INNER JOIN Artist ON Event.ArtistID=Artist.ID WHERE StartDate >= GETDATE() ORDER BY CONVERT(DateTime, StartDate,101) DESC";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
da.Fill(dt);
conn.Close();
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
这是dbController类,它只有一个连接字符串。 (我知道这不是一个好方法,但这只是为了让事情有效)
dbController.cs:
public class dbController
{
//public static string connectionString = "Data Source=SQL5027.myASP.NET;Initial Catalog=DB_A0C908_nbrewer0210;User Id=DB_A0C908_nbrewer0210_admin;Password=fastian123";
public static string connectionString = "Data Source=REDDEVIL/SQLEXPRESS;Initial Catalog=ArtistManagementSystem;User ID=sa;Password=***********";
}
注意:我想提一些事情:
1)我可以使用SqlServer Management Studio连接到数据库。
2)在服务中,SQL Server(SQLEXPRESS)和SQL Server Browser正在运行。
3)在SQL Server配置管理器中,在客户端协议中,TCP / IP&amp;命名管道已启用。
答案 0 :(得分:0)
我有同样的问题。连接字符串中我的服务器名称错误。