更新:我錯過了我應該使用MySql.Data.MySqlClient引用和MySqlConnection,因爲我一直在嘗試連接一個mysql服務器。 Java誤導我,我可以輕鬆地連接兩條線。抱歉花時間**未能將我的網頁連接到數據庫
我試圖將我的網頁連接到數據庫。爲了生成表格,我可以使用java輕鬆連接,但無法使用C#/ Asp連接。
輸出屏幕上的錯誤是:
A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
代碼:
try {
con = new SqlConnection("Data Source = urlhere ;" +
"uid = u_yucel;" +
"pwd = *****; " +
"database = u_yucel; " +
"connection timeout = 2");
cmd.CommandText = "select * from person";
con.Open();
cmd.Connection = con;
DropDownList1.DataSource = cmd.ExecuteReader();
DropDownList1.DataTextField = "name";
DropDownList1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Console.WriteLine("123");
Response.Write(ex.StackTrace);
}
錯誤消息:
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) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at DataDeneme1.carSelect.rebind() in E:\VisualStudioProjects\DataDeneme1\DataDeneme1\carSelect.aspx.cs:line 38
你可以請發佈你正在嘗試使用的連接字符串和一些代碼可能嗎?這非常含糊。謝謝 – Pepe 2011-05-02 19:18:28
對於異常,消息和堆棧跟蹤是什麼?並且,發佈您在該跟蹤中引用的任何代碼。 – 2011-05-02 19:19:26
而實際的異常細節(至少是消息,也許是堆棧跟蹤) – jeroenh 2011-05-02 19:19:44