vb.netsql-server-2012-express

Error in DynamicDatabaseFactory.CreateDatabase connection string parsing


I'm not very familiar with DynamicDatabaseFactory and there isn't a lot of information out there. I'm making changes to a site and I'm just trying to get it to run on my development machine and I've run into this problem, the line: DynamicDatabaseFactory.CreateDatabase(MyConnectionString, DBProviderType.SqlServer) generates this error: [ArgumentOutOfRangeException: Index and length must refer to a location within the string.. I know the connection string is good because it is used in other areas of the application and connects to the database with no problem. In the debugger I can see that the string is being provided properly. So what am I missing?


Solution

  • I was able to get it to work by using one of the overloads to the CreateDatabase method:

    Static db As Database = DynamicDatabaseFactory.CreateDatabase("localhost\SQLEXPRESS", "MYDB", "username", "password", DBProviderType.SqlServer)
    

    This overload allows you to pass the server, database, username and password to the method instead of passing just the connection string. I suspect, but cannot confirm, that the call coded earlier was having a problem parsing the server portion of the connection string, I use Sql Express in my development environment and the database is located at "localhost/SQLEXPRESS", production uses the full version of Sql Server which is located at "localhost". In any event, I was able to get things working with the line of code above.