Reputation: 11
well i have Added PetaPoco.cs file inside my project but when i set the connection string to be used by database Public constructor method ..it show me an error saying that it couldnt connect through database as there is smthing wrong in Connection string (Actually there isnt)
Error Message
Unhandled Exception: System.InvalidOperationException: Can't find a connection string with the name 'Database=database;Data Source=localhost;User Id=root;Password=hamdy33' at PetaPoco.Database..ctor(String connectionStringName) in C:\Users\Hamdy\documents\visual studio 2010\Projects\TEST\TEST\PetaPoco.cs:line 173 at ConsoleApplication1.Program.Main(String[] args) in C:\Users\Hamdy\document s\visual studio 2010\Projects\TEST\TEST\Program.cs:line 15
Program.cs
class Program
{
static PetaPoco.Database db;
static void Main(string[] args)
{
string myConnectionString = "Database=database;Data Source=localhost;User Id=root;Password=hamdy33";
db = new PetaPoco.Database(myConnectionString);
Read("Bank");
}
public static void Read(string TableName)
{
string Query = "SELECT * FROM " + TableName;
foreach (var Entry in db.Query<BankingAccount>(Query))
{
Console.WriteLine(Entry.ToString());
}
}
}
so i'd like to what did i do wrong, and how can i solve this ?
Upvotes: 0
Views: 2107
Reputation: 15987
You are using the wrong overload. The one string overload takes the connection string name that is stored in web.config.
If you want to use the connection string directly, you'll need to pass the provider in as the second argument.
Upvotes: 1