0
votes

I develop my app on my personal computer, then transfer it to my work computer. The code below sets the connection string. The paths are both correct yet I receive the error 52 when testing it on the network.

    Private Function getConnPath()
    Dim WhereAmI As String = Environment.UserName,
        p1 As String = "Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=",
        p2 As String,
        p3 As String = ";Integrated Security=True;Connect Timeout=30",
        r As String
    If Environment.UserName = "Wayne" Then
        p2 = "E:\dbETS.MDF"
    Else
        p2 = "\\americas.com\LIB\Joshua\dbETS.MDF"
    End If
    r = p1 & p2 & p3
    Return r
End Function

enter image description here

I also tried the following connection strings which failed: Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|dbETS.MDF;Trusted_Connection=Yes; Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|dbETS.MDF;Database=dbETS;Trusted_Connection=Yes;

1
I'm not trying to access my database from the internet. It's an mdf file stored on the network drive. It's not a duplicate of that post as I'm not connecting via the internet, and my error code is completely different. - user6376536
Does your work computer have access to the networl drive without the need for credentials? - Josh Part
According to this SO answer localdb is not accessible over a network connection. You could use 'classic' SQL Server Express instead. - peterG
@peterG5 Does that mean that there's no way to access an mdf on a network path? I do not want to install SQL Server or SQL Server Express. - user6376536
@peterG I attempted to do that, and it didn't work. I've revised my post to include my attempts. - user6376536

1 Answers

0
votes

The error might occur for various reasons.But let me just point out the solutions.

1.Make sure Sql server service is running on the machine.

2.Make sure the connection string is correct.For local mdf files,a connection string might look something like :

 "Data Source=.\SQLEXPRESS;
                      AttachDbFilename=c:\folder\SampleDatabase.mdf;
                      Integrated Security=True;
                      Connect Timeout=30;
                      User Instance=True"

3.Make sure you have the permission to access the specific drive/folder

4.If your database requires password and username,make sure they are included in the connection string.

Hope this is somewhat useful :)