CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011
    Posts
    16

    Connecting a VS Studio C# program to a local SQL Server database

    I want to connect this program to a copy of the database on my local machine. I have downloaded SQL Server Express 2005 Management Studio and have made a copy of the database and restored it to my local machine.


    Please would you advise on how I can connect this to the local database. Am I correct in that I need to change some values in the app.config file which is as follows:


    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
    <section name="TestProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
    </sectionGroup>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
    <section name="TestProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    </configSections>
    <connectionStrings>
    <add name="TestProject.Properties.Settings.DBConnection"
    connectionString="Data Source=ServerName;Initial Catalog=FinancialReporting;Persist Security Info=True;User ID=TestId;Password=TestPassword" />
    </connectionStrings>
    <userSettings>
    <TestProject.Properties.Settings>
    <setting name="LastExtract" serializeAs="String">
    <value>2010-08-10</value>
    </setting>
    <setting name="PollingEnabled" serializeAs="String">
    <value>True</value>
    </setting>
    <setting name="PollingInterval" serializeAs="String">
    <value>1</value>
    </setting>
    <setting name="ShowMessage" serializeAs="String">
    <value>False</value>
    </setting>
    </TestProject.Properties.Settings>
    </userSettings>
    <applicationSettings>
    <TestProject.Properties.Settings>
    <setting name="Userid" serializeAs="String">
    <value>TestId</value>
    </setting>
    <setting name="password" serializeAs="String">
    <value>TestPassword</value>
    </setting>
    <setting name="Server" serializeAs="String">
    <value>ServerName</value>
    </setting>
    </TestProject.Properties.Settings>
    </applicationSettings>
    </configuration>



    I am using .NET 3.0.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Connecting a VS Studio C# program to a local SQL Server database

    Change the connectionString to
    Code:
    "Data Source=(local);Initial Catalog=FinancialReporting;..."
    or if the local database has an instance..
    Code:
    "Data Source=(local)\myinstancename;Initial Catalog=FinancialReporting;..."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured