我无法尝试将连接字符串连接到我的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
答案 0 :(得分:1)
假设您可以使用SSMS执行该SQL,我怀疑游览连接字符串不正确。尝试:
myConn = New SqlConnection("Server=SHAREPOINT-TEST\SHAREPOINTTESTSQ;Database=ProblemsAndActions;User Id=myUsername; Password=myPassword;")