0

I am having trouble trying to get my connection string to connect to my SQL Database file here is my code

    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'

Error I keep getting is:

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)

My SQL Server instance Name is SHAREPOINT-TEST\SHAREPOINTTESTSQ

1
  • Ports open in the firewall? Server set up to allow remote connections? Commented Nov 28, 2013 at 13:29

1 Answer 1

1

Assuming you can execute that SQL using SSMS, I suspect that tour connection string is incorrect. Try:

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

Or more details at: http://www.connectionstrings.com/sql-server/

Sign up to request clarification or add additional context in comments.

7 Comments

Hello Dd2, Thank you for your help but it seams to be now giving my a different error message ;Login Failed for User "sa"
I suppose you can connect via ssms with those credentials?!
Hello Dd2 Yes I can connect via ssms with these credentials
Are u using SQL Server Express Edition?
@BennjaminMiles 'Login Failed for User "sa"' Means that something else is going wrong. If this login works in SSMS ("sa"+password), then use this to connect to the server with SSMS and check the SQL Server error logs. They are under the "Management" folder and labelled "SQL Server Logs". Open the Current one and search for your login failure message. Immediately before it in the log and with the same timestamp should be another message that looks like "Error: 18456, Severity: 14, State: <#>." Find that state number and tell us what it is.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.