簡體   English   中英

SQL連接字符串到SQL Server數據庫

[英]SQL Connection String to SQL Server Database

我在嘗試獲取連接字符串以連接到我的SQL數據庫文件時遇到麻煩,這是我的代碼

    Dim myConn As SqlConnection

    Dim cmd As SqlCommand

    Dim sqlstring as string


    'Difines what database i would like to use '
    myConn = New SqlConnection("Data Source=SHAREPOINT-TEST;AttachDbFilename=\\sharepoint-test\SPD\MSSQL\Data\ProblemsAndActions.mdf")
    'Opens the connection to the database'
    myConn.Open()
    'inserts into database what table and what information relevant to what variable line in table Master'
    sqlstring = "INSERT INTO Master (Id, Raised_By, Customer, Complainant_Details, Product_Code_Affected, Description_Of_Product, Qty_Affected, Batch_Affected, End_Customer, Order_Number, Consignment_Number, Details_Of_Complaint, Severity_Rating) VALUES ('" + L1 + "','" + L2 + "','" + L3 + "','" + L4 + "','" + L5 + "','" + L6 + "','" + L7 + "','" + L8 + "','" + L9 + "','" + L10 + "','" + L11 + "','" + L12 + "','" + L13 + "')"
    cmd = New SqlCommand(sqlstring, myConn) 'comands to insert the above line ^'
    cmd.ExecuteNonQuery() 'execute the command'
    myConn.Close() 'closes connection to database'

我一直得到的錯誤是:

建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱正確,並且已將SQL Server配置為允許遠程連接。 (提供者:命名管道提供程序,錯誤:40-無法打開與SQL Server的連接)

我的SQL Server實例名稱為SHAREPOINT-TEST\\SHAREPOINTTESTSQ

假設您可以使用SSMS執行該SQL,我懷疑游覽連接字符串不正確。 嘗試:

myConn = New SqlConnection("Server=SHAREPOINT-TEST\SHAREPOINTTESTSQ;Database=ProblemsAndActions;User Id=myUsername; Password=myPassword;")

或更詳細的信息,請訪問: http : //www.connectionstrings.com/sql-server/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM