0

I'm using the Simple.Data ORM to hook up a database from within the Visual Studio environment that's defined in a local sql file (named convertcsv.sql). I'm following the instructions detailed here, and thus far, I've installed Simple.Data.SqlServer and Simple.Data.Ado via NuGet, have the following in my App XML file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
<connectionStrings>
    <add name="Simple.Data.Properties.Settings.DefaultConnectionString"
    connectionString="convertcsv" />
</connectionStrings>

I have the following in my Program.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Simple.Data;

namespace DatabaseWalkthrough{
    class Program{
        static void Main(string[] args){
            var db = Database.Open();
            var tmp = db.mytable.FindAll(db.mytable.NC == 505);
            foreach (var d in tmp){
                Console.WriteLine(d.NC);
                Console.ReadKey();
            } 
        }
    }

}

NOTE: In the convertcsv.sql file, there is only one table (mytable) and NC is one of its well-defined fields containing integral values.

At the line where the foreach loop is initialized, the debugger alerts the following error:

Additional information: Format of the initialization string does not conform to specification starting at index 0.

A little bit of sleuthing reveals this Stack Overflow question a similar problem, but that particular instance of the error appears to have been caused by improper credentials to access a database on a server, whereas I'm trying to propagate a database into my C# app in Visual Studio to update it.

I have the following hypotheses for why this could be an issue:

1) The App config XML file cannot locate the convertcsv.sql file. Somewhat unlikely since I preemptively added this file into all of the project subdirectories.

2) Missing parameters - this is possible since I've seen some variation for how DB connections are arranged in the App config file, but the Simple.Data documentation is somewhat translucent.

Any other ideas?

Community
  • 1
  • 1
Adam Freymiller
  • 1,929
  • 7
  • 27
  • 49
  • Isn't the connection string from the first code block in this question? Or does it refer to something else? – Adam Freymiller Jun 24 '16 at 17:59
  • Sorry but connectionstring="convertcsv" is not a proper connection string, a connection string must have some basic segment, you can search in Google as how to define a connection string – krish Jun 24 '16 at 18:21
  • Based on this response (http://stackoverflow.com/questions/3159093/how-to-define-a-connection-string-to-a-sql-server-2008-database), I changed the connectionString attribute to connectionString="server=(local);database=convertcsv;integrated security=SSPI". The execution isn't printing out any of my expected output, although it does output to the console "DatabaseWalkthrough.vshost.exe' has exited with code -1073741510 (0xc000013a)." Intuitively, I think that database=convertcsv.sql is wrong, but if that's the case, how do I set up connection to the data in my SQL file? – Adam Freymiller Jun 24 '16 at 18:53
  • Actually you haven't had your connection setup when you called database.open(). The code actually setup a connection when you start to iterate your results in for each loop.probably lazy loading is used in simple.data – krish Jun 24 '16 at 19:00
  • SimpleData documentation is now on https://scottleslie.github.io/simplefx.github.com/simpledata/docs/index.html – oaamados Dec 17 '19 at 05:15

0 Answers0