Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

ASP.NET與SQL Server 2005 連接

資料庫∶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連接設定? (拜托,詳細些)

Update:

首先非常感謝 網頁程式設計 的解答,

相關資訊:

Full computer name: Snoopy(不是之前寫的"none")

Windows User Account(For login window): Alien Workshop

Database: Student.mdb

SQL SERVER 2005 EXPRESS 安裝時設置:

User ID: SA(預設),Password:12345

Update 2:

我做了以下修改,

在Control Panel的ODBC Data Source設置一個新的System DNS, 以SQL Server做為Driver連接去SQL Server: SNOOPY\SQLEXPRESS

選擇With Window NT Authentication Using the network login ID

然後default database to: Student.mdb 然後 Finish

Update 3:

ConnString = "Data Source=snoopy\sqlexpress;User ID=SA;Password=12345;Initial Catalog=Student"

結果還是失敗Login failed for user 'SA'. The user is not associated with a trusted SQL Server connection.

Update 4:

如果修改為您建議的ConnString" 則結果是Cannot open database "TestDB" requested by the login. The login failed. Login failed for user 'sa'.

3 Answers

Rating
  • 1 decade ago
    Favorite Answer

    錯誤訊息有寫得很清楚,您的SQL SERVER不允許遠端連結!(SQL Server does not allow remote connections)

    請您改用 TCP/IP的方式,直接連結他的IP位址或是 Localhost。

    <%

    '註解:第一,連結SQL資料庫

    Dim strConn As String = "server=localhost; uid=帳號; pwd=密碼; database=資料庫名稱"

    Dim Conn As SQLConnection = New SQLConnection(strConn)

    Conn.Open()

    %>

    以ASP.NET 2.0來說,也可以寫在 Web.Config檔案裡面,然後用這種方式來呼叫他。

    <%

    '== 連結資料庫的連接字串 ConnectionString ==

    'SqlDataSource1.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString

    %>

    用 Visual Studio 2005就會有精靈帶著你一步一步的作,您把結果COPY下來用就好了。

    ................................................................................................

    我的 ASP.NET教學網站,有空來看看吧~ http://www.taconet.com.tw/mis2000_aspnet/

    Source(s): 我的 ASP.NET教學網站,有空來看看吧~ http://www.taconet.com.tw/mis2000_aspnet/
  • Anonymous
    5 years ago

    到下面的網址看看吧

    ▶▶http://qoozoo09260.pixnet.net/blog

  • ?
    Lv 5
    1 decade ago

    SQL SERVER

    有二種連線方式,

    一種是windows証認,

    另一種是混合式認証(sql認証)

    請你確認一下你的認証方式是否為混合式認証

    如此才能用asp.net連線

    Source(s): me
Still have questions? Get your answers by asking now.