Using SqlBuilder without Database object. #57
-
I just need SqlBuilder without the database connection part. I am generating a query string but without the use of the Database object it never fully builds the command. Is there a way around this? I'm doing my own connection code already, just ran into the issue of dynamically creating queries. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
You can pass your existing connection to the Database constructor. |
Beta Was this translation helpful? Give feedback.
-
When I try to create a new Database() object, but I'm getting an error that I need a default connection name key in appSettings configuration section. I've looked through the documentation and cannot find anything that references this. |
Beta Was this translation helpful? Give feedback.
-
You said you already have a connection, then do this: var db = new Database(conn); BTW, what version are you using? |
Beta Was this translation helpful? Give feedback.
-
Yes but my connection that I already have isn't using DbExtensions, sorry should have been clear. I'm using System.Data.SqlClient SqlConnection for that. So what I was trying to do was create a Database using the connection string that I have built ""Server=..., ...;Database=...;User ID=...;Password=..;" format. Maybe I'm just really confused about how to use DbExtensions. Basically what I'm trying to use it for is just to build a SQL Query to use in my own stuff, with the connection I have set up. |
Beta Was this translation helpful? Give feedback.
-
I'm using this in conjunction with Unity so I'm stuck in .NET3.5 so DbExtensions v4. |
Beta Was this translation helpful? Give feedback.
-
In v4 you don't need Database, call ToCommand and pass your SqlConnection. See: https://github.com/maxtoroq/DbExtensions/blob/v4/docs/SqlBuilder.md |
Beta Was this translation helpful? Give feedback.
-
Okay this is leading me in the right path, but I'm still getting the an error. "ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider 'System.Data.SqlClient.SqlConnection' System.Data.COmmon.DbProviderFactories.GetFactory(System.String providerInvariantName) Any ideas? Also, thank you so much for your help, been stuck on this for a while. |
Beta Was this translation helpful? Give feedback.
-
That's weird. Try passing |
Beta Was this translation helpful? Give feedback.
-
Okay that worked! Thank you for your help, I appreciate it! |
Beta Was this translation helpful? Give feedback.
That's weird. Try passing
SqlClientFactory.Instance
instead.