NEventStore problem configuring SQL dialect - event-sourcing

I am working on a prototype CQRS implementation and trying to use Jonathan Oliver's event store with MS SQL server:
_store = Wireup.Init()
.UsingSqlPersistence("EventStore")
.InitializeDatabaseSchema()
.UsingJsonSerialization()
.Build();
I have a matching connection string defined in app.config:
<connectionStrings>
<add name="Business.Domain.Repository.Tests.Properties.Settings.EventStore"
connectionString="Data Source=EventStore.sdf;" />
</connectionStrings>
I have tried variations of connection strings for SQL CE, local SQL, remote SQL server's and always get this error:
System.NullReferenceException was caught
Message=Object reference not set to an instance of an object.
Source=EventStore
StackTrace:
at EventStore.Persistence.SqlPersistence.SqlPersistenceFactory.GetDialect() in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Persistence.SqlPersistence\SqlPersistenceFactory.cs:line 53
at EventStore.Persistence.SqlPersistence.SqlPersistenceFactory.Build() in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Persistence.SqlPersistence\SqlPersistenceFactory.cs:line 46
at EventStore.SqlPersistenceWireup.<>c__DisplayClass4.<.ctor>b__1(NanoContainer c) in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Wireup\SqlPersistenceWireup.cs:line 13
at EventStore.ContainerRegistration.Resolve(NanoContainer container) in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Wireup\NanoContainer.cs:line 66
at EventStore.NanoContainer.Resolve[TService]() in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Wireup\NanoContainer.cs:line 40
at EventStore.PersistenceWireup.Build() in c:\Projects\Business\Proto1\EventStore\src\proj\EventStore.Wireup\PersistenceWireup.cs:line 47
Has anyone come across this before or have an idea what I am doing wrong? I tried stepping through the source and still not sure why there is a null reference.
-Steve

I'm updating some of the error handling now surrounding dialect detection. You'll need to add a "providerName" to your connection string, e.g.:
<add name="Business.Domain.Repository.Tests.Properties.Settings.EventStore"
providerName="System.Data.SqlServerCe.3.5"
connectionString="Data Source=EventStore.sdf;" />
Having the providerName attribute in the connection configuration allows the EventStore to know which driver to use when connecting to your database instance.

Related

Mule ESB does not able to pass a message property as input in Oracle Store Procedure

Good morning everybody,
I have a question for you about the mule's behviour when it has to execute a Oracle Store Procedure in MuleEE 3.4.
In my application I should invoke a Store Procedure in a Oracle Database and I should pass it an input variable (mule message id) and this procedure should return a value (0) in an output variable passed also itself in the store procedure as out variable. The code below shows this:
<jdbc-ee:outbound-endpoint exchange-pattern="request-response" queryTimeout="-1" connector-ref="JdbcConnector" doc:name="Database" queryKey="CallProcedure">
<jdbc-ee:query key="CallProcedure" value="Call analyze_buffer_sbil_zonali(#[#[message.outboundProperties['massageID']];string;in],#[mules2;int;out])"/>
</jdbc-ee:outbound-endpoint>
The problem is that I get this error when I try to excetue this query:
Root Exception stack trace:
java.sql.SQLException: Parameter IN or OUT missing in the index:: 2
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:1680)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
I really do not how this exception is thrown. I followed the mule documentation (JDBC Transport Reference) and I tried other variants of this query, but no changed occurred.
I've stopped here in development and I do not know how to carry on without using a Java class that implements this behaviour.
Does anybody any idea?
I look forward to hearing you,
thank you so much in advance

Mule ESB simple jdbc insert

I'm trying to force Mule ESB Studio, to perform some simple insert into a jdbc. My goal is to open a page in my webbrowser, let's say it's http://localhost:8081/, and then Mule ESB performs insert 'foobar' value into database.
Here's my code:
<jdbc-ee:mssql-data-source name="MS_SQL_Data_Source" user="esbtest" password="Test123" transactionIsolation="NONE" doc:name="MS SQL Data Source" loginTimeout="10000"
url="jdbc:sqlserver://10.1.212.42:1433;databaseName=test"></jdbc-ee:mssql-data-source>
<jdbc-ee:connector name="Database" dataSource-ref="MS_SQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
<flow name="Test_PierwszyFlow1" doc:name="Test_PierwszyFlow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" mimeType="text/plain"></http:inbound-endpoint>
<object-to-string-transformer doc:name="Object to String"/>
<jdbc-ee:outbound-endpoint exchange-pattern="one-way" queryTimeout="-1" doc:name="Database" connector-ref="Database" queryKey="insertQuery">
<jdbc-ee:query key="insertQuery" value="INSERT INTO t_Login (login) VALUES ('foo bar')"/>
</jdbc-ee:outbound-endpoint>
</flow>
I've not specified any beans or such things. In logs, I see these lines:
INFO 2013-07-02 11:20:37,550 [[test_pierwszy].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'Database.dispatcher.1938839184'. Object is: EEJdbcMessageDispatcher
INFO 2013-07-02 11:20:37,550 [[test_pierwszy].connector.http.mule.default.receiver.02] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'Database.dispatcher.1938839184'. Object is: EEJdbcMessageDispatcher
INFO 2013-07-02 11:20:37,670 [[test_pierwszy].connector.http.mule.default.receiver.02] com.mulesoft.mule.transport.jdbc.sqlstrategy.UpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
INFO 2013-07-02 11:20:37,730 [[test_pierwszy].connector.http.mule.default.receiver.02] com.mulesoft.mule.transport.jdbc.sqlstrategy.UpdateSqlStatementStrategy: Executing SQL statement: 1 row(s) updated
...but my database is empty! I must say, I am totally new in Mule ESB area and have no idea what is wrong. Please - help.
Edit: Funny thing is, that when I change talbe or column name to something, that does not exist, I get JDBC error corresponding to that matter.
Second question is, how to inject to DB value I've specified in URL? For example, when I type in browser http://localhost:8081/foo, the value foo is passed to jdbc outcome connector, and 'foo' value is inserted.
Thanks in advance.
I'm guessing uncommitted transaction here. Try adding transactionPerMessage="true" to your <jdbc-ee:connector...
I noticed similar issue in Mule-EE, Mule-CE works fine...
When you call jdbc:outbound-endpoint with an ArrayList payload but use SESSION/INVOCATION variables as params in your SQL query, I noticed it has no effect on the table in question (no Insert/Update) yet logger records "Record Updated".
Changing payload to other type of an Object for this jdbc call solved the issue.
To keep an open mind, consider:
-passing SQL query parameters via a Payload instead
-consider message enrichers

Linq Dynamic ConnectionString Application Settings

I want to read my connection strings from the Web.config or App.Config file. I attempted to follow the advice in another Stackoverflow post.
The suggestion was to:
Set Application Settings in the Linq to Sql DBML file to false. (Double-click on the Linq to Sql file to open it, right-click on white space in the designer surface, select Properties, expand Connection property. )
Set Connection to (None) in the Linq to SQL DBML file.
Add an OnCreated event method in the data context partial class to read the connection string from web.config or app.config.
When I make the above changes and attempt to compile my code I get:
Error 2 Expression of type 'Object' is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider.
The error occurs on the 2nd line below:
Using DcObj = New HMR_LinqToSql_QuestionDataContext()
Dim Query = From Q In DcObj.tblQuestions Select Q ' *** Error on this line
Count = Query.Count()
DcObj.tblQuestions.DeleteAllOnSubmit(Query)
DcObj.SubmitChanges()
End Using
The only way, I found, to clear the error is to set Application Settings to True and select a connection string entry in the Connection drop down list. If I revert to Application Settings = True that mean there is still connection strings in the Linq to Sql files.
Any ideas for a solution?
Ed

Unable to load connection string using xRM data context

Edited to add solution:
changed to use the constructor that takes a Microsoft.Xrm.Client.CrmConnection rather that a String connection string and it works.
I used the crmsvcutil.exe to generate the data context for our crm environment. When I try to initialize the connection.
This line:
public CSIDataContext(global::System.String name)
: base(name)
throws this error:
Unable to load the connection string name 'Authentication Type=AD; Server=/rest of conn string is here/'
This code resides in a BizLayer class library project and is being called from a win form test project. If both the generated entities class and the calling code are in the same project, I don't get that error.
It sounds like you're passing the full connection string in the constructor rather than the name of the connection string in the connectionStrings node of the app.config/web.config.
The XRM connection string is very similar to an ADO.NET connection string in that it resides in the element in the app.config/web.config. So, you would normally place the full connection string into your config with a name like so:
<connectionStrings>
<add name="XrmConnectionString" connectionString="Authentication Type=AD; Server=http://server.com; User ID=Domain\Username; Password=P#$$w0RD"/>
</connectionStrings>
Then, when you want to initialize the XRM context, you just supply the connection string's name:
var dataContext = new XRMDataContext("XrmConnectionString");
Try that and see if it works for you.

Dynamic LINQ context

I'm trying to figure out how to create a dynamic context, and what I mean by that is I have two databases: one for testing, and one for production. Depending on where my website is hosted, I want my context to be pointing at one of the two. So, in my web.config I have:
<add name="Testing_ChannelsEntities" connectionString="removed for brevity" providerName="System.Data.EntityClient" />
<add name="Production_ChannelsEntities" connectionString="removed for brevity" providerName="System.Data.EntityClient" />
Please don't get hung-up on the fact that I removed the connectionString for this example. Just note that I have a testing and a production connection in the web.config.
So, here is my codebehind that I would expect to create a context to the testing connectionString:
using (ChannelsEntities chEntity = new ChannelsEntities("Testing_ChannelsEntities")) {
// removed the business logic because it's not relevant at all
}
Once execution hits the using statement, I get the following error:
Format of the initialization string does not conform to specification starting at index 0.
What am I missing here? This should be easy to do.
I've done similar. Try this -
using (ChannelsEntities chEntity = new ChannelsEntities("name=Testing_ChannelsEntities")) {}
Try:
using (ChannelsEntities chEntity = new ChannelsEntities(WebConfigurationManager.ConnectionStrings["Testing_ChannelsEntities"].ConnectionString)) {
// removed the business logic because it's not relevant at all
}
We put our connection string in a root web.config. You can reference the connection string by name in your virtual diectory and it will inherit the settings from your root web.config.

Resources