Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an application to store documents in a FILESTREAM database. I have created the database and I have inserted a few records into this database using an SQL query. But for some reason I cannot open the database in a Visual Basic application to even get started to manipulate the data.
Here is the code, I have used this basic code in several other applications, and it works fine:

Imports System.Data.SqlClient
Imports System.Drawing
Imports System.IO

Module Program
    Sub Main()
        'Create a connection to the database
        Dim ConStr As String = "Data Source=DESKTOP-UAB5C74\SQLEXPRESS;
            Initial Catalog=I:\MyFileCabinet\MyFileCabinet; 
            Integrated Security=True"
        'Create a new SQLConnection
        Dim con As New SqlConnection(ConStr)
        'Open Database with error catching
        Try
            con.Open()
        Catch ex As Exception
            Console.WriteLine("Open Error" + ex.Message)
            Exit Sub
        End Try
        Console.WriteLine("File Opened")
        'Cleanup
        con.Close()
    End Sub
End Module

When I debug the application, I get the following error:
"Open error, cannot open database "I:\MyFileCabinet\MyFileCabinet" requested by the login
The login failed for user ‘DESKTOP-UAB5C74\Brown’"


What I have tried:

I have made sure that user ‘DESKTOP-UAB5C74\Brown’ is the owner of the .dbf file and the log file, and that user has full rights to these files.
I have checked database properties to be sure the connection string was correct.

I have no idea where to go from here, any help would be greatly appreciated.
Posted
Updated 3-Mar-21 20:23pm
Comments
shanda watkins 3-Mar-21 16:12pm    
The error is not wrong. You are connecting via sql, so setting owner of a dbf file means nothing. You need to make sure your account has permissions in sql. Use Sql Management Studio to do so.
Member 10376725 5-Mar-21 11:30am    
shanda watkins, I am not sure what you are saying, how do I make sure my account has permission in SQL? I have worked with a few SQL databases and have never come across that.

1 solution

You need to change connection string. Proper connection string looks like this:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

More at: SQL Server connection strings - ConnectionStrings.com[^]

In a short: MS SQL server instance have to be running and have to be accessible in LAN/from WAN!

I'd suggest to read this:
Configure the remote access Server Configuration Option - SQL Server | Microsoft Docs[^]
Configure Windows Firewall - SQL Server | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 10376725 5-Mar-21 8:37am    
Did not make a difference, still get same error message.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900