2013-11-28 243 views
0

我有麻烦试图让我的连接字符串连接到在这里我的SQL数据库文件,SQL Server数据库是我的代码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' 

错误我不断收到的是:

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)

我的SQL Server实例名称是SHAREPOINT-TEST\SHAREPOINTTESTSQ

+0

防火墙中的端口打开:在

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

或者更多的细节?服务器设置为允许远程连接? –

回答

1

假设您可以使用SSMS执行该SQL,我怀疑巡视连接ction字符串不正确。尝试: http://www.connectionstrings.com/sql-server/

+0

您好Dd2,感谢您的帮助,但它现在给我一个不同的错误信息;用户登录失败“sa” –

+0

我想你可以通过ssms连接这些凭据? –

+0

你好Dd2是的,我可以通过ssms连接这些凭据 –