locked
Accessing SQL (.mdf) Files with VB Program RRS feed

  • Question

  •  

    Hi, I am attempting to access an SQL (.mdf) file I have created with the Database Explorer utility of Visual Basic.  Here is some relevant code from the program:

    Imports System.Data.SqlClient

    Dim Database01 As SqlConnection = New SqlConnection("Data Source=C:\Test01.mdf")

    SMUDatabase01.Open()

    At this last line of code, I get the following error message:

    “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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)”.

    I am using Windows Vista OS and the firewall is turned off.

    I suspect the problem might be the settings (such as connection strings) within the app.config file, but if so I am unsure what the correct coding within this file should be to access the file.  Any suggestions?  Thanks.


    Michael Downing

    Friday, February 10, 2012 11:17 PM

Answers

  • Yes I do agree this is becoming distorted from the original question; I can’t understand why accessing and manipulating SQL files with a VB program should be so much more complex than using Access, Excel, text files, etc.  I have used these types of files within VB programming for years without problem.

    I will open a new thread; however I have raised the issue within the SQL Server forum of the ASP.net website and the same kind of digression of discussion occurred.  (I have the same problem within both Visual Basic and Visual Studio applications.)  Thanks.


    Michael Downing

    • Marked as answer by Oakwinds Tuesday, February 14, 2012 3:15 PM
    Monday, February 13, 2012 11:55 PM

All replies

  • On 2/10/2012 6:17 PM, Oakwinds wrote:
    > Hi, I am attempting to access an SQL (.mdf) file I have created with the
    > Database Explorer utility of Visual Basic.Here is some relevant code
    > from the program:
    >
    > Imports System.Data.SqlClient
    >
    > Dim Database01 As SqlConnection = New SqlConnection("Data
    > Source=C:\Test01.mdf")
    >
    > SMUDatabase01.Open()
    >
    > At this last line of code, I get the following error message:
    >
    > “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: SQL Network
    > Interfaces, error: 26 - Error Locating Server/Instance Specified)”.
    >
    > I am using Windows Vista OS and the firewall is turned off.
    >
    > I suspect the problem might be the settings (such as connection strings)
    > within the app.config file, but if so I am unsure what the correct
    > coding within this file should be to access the file.Any suggestions?Thanks.
    >
     
    Most would attach that MDF file to a SQL Server database and access the
    database through an instance of SQL server running locally or remotely
    on  a machine. The MDF file would be moved  to the SQL directory where
    the rest of the MDF files are located that are attached to SQL server.
     
     
     
    Friday, February 10, 2012 11:55 PM
  •  

    OK, let me back up then to a question about installing SQL Server in order to get to the SQL Server Management Studio Object Explorer to perform the attachment process.  From the SQL Server Installation Center application, I get the pop-up Browse For Folder > Browse for SQL Server 2012 RC0 Installation Media.  Where is the correct folder located to continue the installation process?  Thanks.


    Michael Downing

    Saturday, February 11, 2012 2:04 PM
  • Saturday, February 11, 2012 6:13 PM
  • test

    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, February 11, 2012 6:15 PM
  • copied and pasted from this link and blew it up.

    http://msdn.microsoft.com/en-us/library/ms190629.aspx


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Saturday, February 11, 2012 6:23 PM
  • OK – when I follow the procedure “Starting the Correct Instance of SQL Server” in the link provided, the Windows pop-up produced is titled “SQL Server”, but only shows an “X” within a red circle without further explanation, and with “OK” the only option.  I assume this represents a problem but am unsure how to resolve.  The path is:

     C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe.


    Michael Downing

    Monday, February 13, 2012 2:07 PM
  • Does this thread appear distorted to you?  It does for me.  Start a new thread. 

    Rudy   =8^D


    Mark the best replies as answers. "Fooling computers since 1971."

    http://thesharpercoder.blogspot.com/

    Monday, February 13, 2012 10:33 PM
  • Yes I do agree this is becoming distorted from the original question; I can’t understand why accessing and manipulating SQL files with a VB program should be so much more complex than using Access, Excel, text files, etc.  I have used these types of files within VB programming for years without problem.

    I will open a new thread; however I have raised the issue within the SQL Server forum of the ASP.net website and the same kind of digression of discussion occurred.  (I have the same problem within both Visual Basic and Visual Studio applications.)  Thanks.


    Michael Downing

    • Marked as answer by Oakwinds Tuesday, February 14, 2012 3:15 PM
    Monday, February 13, 2012 11:55 PM