頁: [1]
|
 |
|
作者
|
主題: 求助∶ ASP.NET與SQL Server 2005 連接 (閱讀 1701 次)
|
msy
小學生
離線
文章: 1
|
資料庫∶Student.mdf User ID∶SA Password∶12345
連接程式碼∶
Dim ConnString As String ConnString = "Data Source=None;" & _ "User ID=SA;Password=12345;" & _ "Initial Catalog=Student" MyCon=New SqlConnection(connstring) Mycon.Open()
結果與資料庫的連接設定出現問題,
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
請問要如何更正SQL Server連接設定? (拜托,詳細些)
|
|
|
|
|
已記錄
|
|
|
|
|
小誌
|
Express、Evaluation 以及 Developer 版本預設只允許本機用戶端連接。 Enterprise、Standard 以及 Workgroup 版本可接聽透過 TCP/IP 連接的遠端用戶端連接。
在SQL Server 2000裡面只要從enterprise manager裡面點選要開放的server, 右鍵->內容就可以設定了. SQL Server 2005要如何啟動remote connection呢? 1.開始->程式集->Microsoft SQL Server 2005->組態工具 選擇SQL Server Configuration Manager與SQL Server 介面區組態
2.在SQL Server 介面區組態裡面,選擇「服務與連接的介面組態」
3.左邊先選擇遠端連接,右邊點選本機與遠端連接->只使用TCP/IP
4.在SQL Server Configuration Manager左邊點選MSSQLSERVER的通訊協定, 右邊選選TCP/IP,右鍵->啟用
如此一來,你的SQL Server 2005就可以遠端連接囉!
|
|
|
|
|
已記錄
|
|
|
|
|
阿草
|
我照第二篇改過以後還是有問題呢
我按設計還是會出現ERROR40
'/guest' 應用程式中發生伺服器錯誤。 --------------------------------------------------------------------------------
在建立連接至伺服器時發生錯誤。當連接至 SQL Server 2005 時,失敗的原因可能是,在預設設定下,SQL Server 不允許遠端連接。 (provider: 具名的管線提供者, error: 40 - 無法開啟至 SQL Server 的連接) 描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。
例外詳細資訊: System.Data.SqlClient.SqlException: 在建立連接至伺服器時發生錯誤。當連接至 SQL Server 2005 時,失敗的原因可能是,在預設設定下,SQL Server 不允許遠端連接。 (provider: 具名的管線提供者, error: 40 - 無法開啟至 SQL Server 的連接)
原始程式錯誤:
只有在偵錯模式編譯時,才可以顯示產生此未處理例外狀況的原始程式碼。若要啟動,請依照下列步驟之一,然後要求 URL:
1. 將 "Debug=true" 指示詞加入產生錯誤的程式碼頂端。例如:
<%@ Page Language="C#" Debug="true" %>
或:
2. 將下列區段加入您應用程式的組態檔:
<configuration> <system.web> <compilation debug="true"/> </system.web> </configuration>
請注意: 第二種技巧會導致在偵錯模式下編譯指定應用程式中的所有檔案。第一種技巧只會造成在偵錯模式下編譯該特定檔案。
重要資訊: 在偵錯模式下執行應用程式會過度耗用記憶體/效能。在實際執行部署之前,應該先確認應用程式已經停止偵錯。
堆疊追蹤:
[SqlException (0x80131904): 在建立連接至伺服器時發生錯誤。當連接至 SQL Server 2005 時,失敗的原因可能是,在預設設定下,SQL Server 不允許遠端連接。 (provider: 具名的管線提供者, error: 40 - 無法開啟至 SQL Server 的連接)]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +173 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199 System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +348 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +160 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +361 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +184 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +196 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +502 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +28 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +429 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +70 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +510 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +85 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +89 System.Data.SqlClient.SqlConnection.Open() +160 ASP.guest_aspx.connection_outmessage() +53 ASP.guest_aspx.Page_Load(Object sender, EventArgs e) +25 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43 System.Web.UI.Control.OnLoad(EventArgs e) +80 System.Web.UI.Control.LoadRecursive() +49 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3750
-------------------------------------------------------------------------------- 版本資訊: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433
|
|
|
|
|
已記錄
|
|
|
|
|
小誌
|
我照第二篇改過以後還是有問題呢
我按設計還是會出現ERROR40
這還是因為無法連接資料庫啦,有沒有裝防毒或防火牆軟體? 試著先關閉防毒或防火牆軟體並檢查SQL Server是否正確設置
|
|
|
|
|
已記錄
|
|
|
|
|
小誌
|
'建立資料庫連線 Dim MyCon As SqlConnection Dim ConnString As String ConnString = "Data Source=None;" & _ "User ID=SA;Password=12345;" & _ "Initial Catalog=Message" MyCon = New SqlConnection(connstring) Mycon.Open() '-----------------
看一下上面這段原始碼,Data Sourse是SQL Server的名稱,你有改成你自己的SQL Server名稱嗎?不會還是用 None吧??
|
|
|
|
|
已記錄
|
|
|
|
|
阿草
|
我有把IIS的主目錄路徑改成桌面我放專題檔案的資料夾不知道是不是這的問題? C:\Documents and Settings\Administrator\桌面\大學城系統 我防火牆都有關閉了 跟TCP/IP那的設定都開哩 SQL SERVER 那邊SA密碼也是12345 資料庫也匯入message mark 起來用瀏覽器預覽可以跑出來 http://stweb.ydu.edu.tw/~94404509/2.JPGbut點網友留言就會錯誤 http://stweb.ydu.edu.tw/~94404509/3.JPG不知哪邊有問題 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' <%@ Import Namespace = "System.Data" %> <%@ Import Namespace = "System.Data.SqlClient" %> <Script Language="VB" Runat="Server"> Sub addPost(sender As Object,e As EventArgs) '建立資料庫連線 Dim MyCon As SqlConnection Dim ConnString As String ConnString = "Data Source=localhost;" & "User ID=sa;Password=12345;" & "Initial Catalog=message" MyCon = New SqlConnection(ConnString) Mycon.Open() '----------------- '建立Command物件 Dim MyCommand As New SqlCommand '指定連結資料庫的物件為Mycon MyCommand.Connection=Mycon '指定SQL指令敘述 Dim MySQL As String MySQL="Insert Into allmessage (網友姓名, 留言主題, 聯絡信箱, 留言內容, 私人公開, 圖形) Values (" MySQL=MySQL & "@name,@Subject,@email,@Memo,@personal,@pic)" MyCommand.CommandText=MySQL '把各個欄位的資料指定給Command物件的『Parameters』屬性 MyCommand.Parameters.Add("@Name",SqlDbType.nvarchar,16).Value=name.Text MyCommand.Parameters.Add("@Subject",SqlDbType.nvarchar,100).Value=subject.Text MyCommand.Parameters.Add("@email",SqlDbType.varchar,50).Value=email.Text MyCommand.Parameters.Add("@Memo",SqlDbType.nvarchar,500).Value=Replace(memo.Text,vbCrLf,"<BR>") MyCommand.Parameters.Add("@personal",SqlDbType.bit,1).Value=personal.SelectedIndex MyCommand.Parameters.Add("@pic",SqlDbType.varchar,2).Value=pic.SelectedItem.Value '執行SQL命令,將資料寫入資料庫 MyCommand.ExecuteNonQuery() '網頁轉向 Response.Redirect("guest.aspx") End Sub </Script>
|
|
|
|
|
已記錄
|
|
|
|
|
小誌
|
凹在這裡是沒用的,先簡單的寫個程式 嘗試跟SQL連線,看看能否成功,先確定SQL SERVER能連線再說
|
|
|
|
|
已記錄
|
|
|
|
|
頁: [1]
|
|
|
|