Connection fails, database has '.' in name - ruby-on-rails

I've been trying to debug a SQL Server database error in one of our rails apps. The problem is that the database name, as added in database.yaml, has a '.' in it ('testdb.v1'). It results in the error:
TinyTds::Error: Database 'testdb' does not exist. Make sure that the name is entered correctly.
Thinking that this was a YAML vs. Rails issue with quoting of the '.' character, I opened the app in rails console and tried every kind of Ruby quoting I could think of, but I get the same error each time.
Somewhere down the line from the assignment of the database name in my model.connection_config, the '.' is being interpreted as a format specifier and the suffix is dropped from the name. model.connection_config['database'] has 'testdb.v1', as it should, but clearly that's not what's being handed to SQL Server.
I wasn't sure if this is a rails issue or a SQL Server issue, though a C# app I tossed together manages to open the database without problems. Thus, I assume it's a rails/ActiveRecord issue. Unfortunately, I don't have the option of changing the database name.
Is there a way to quote the '.' character so that it will maintain the '.' and the suffix in the database name?

Further investigation took me to the github page for the activerecord-sqlserver-adapter
There, I found issues 230 and 226, with similar problems to mine. Apparently using '.' in database, table or column names will present similar problems. As these were created in 2012 and are still open, it doesn't look like a fix is coming anytime soon. In the comments there are a few ideas to monkey-patch it into working. Guess that's the approach I'll have to take to get this working.
UPDATE: For anyone stuck with a similar problem, and the database name is the only issue (not tables or columns), the solution we went with was an end-run around the sqlserver-adapter. We created a SQL user for each database, and assigned a default database to that user. Then, we connected with the user login but left the database name null. SQL Server will connect to the default database in that case.

Related

Column names in each table must be unique. Column name 'CategoryId' in table 'Products' is specified more than once. Migration Update Issue

I am using visual studio with sql server, i am in a middle of a practice and faced a major issue.
The issue was in the first place, when i was creating a product table , by mistake i mistyped as a categoryId ctegoryId, and later i recorrected it by thinking its over.
And now I am almost done with the identity scaffolding when updating my database, I am facing such an error. and I've tried all ways to update it by myself but failed.
I need an expert guidance so I can continue my path till the end.
I do appreciate any solution from your side.
Thanks indeed [Migration error "Each Table must be unique"](https://i.stack.imgur.com/tB3iT.png)
Just to let you know, I have deleted my migration and reinstalled again without[NotMapped]in my product table"categoryID" and it worked back normally.

Webmatrix 3 hangs while querying cmsDocument table in SQL Server CE Database Umbraco

Webmatrix is hanged while I query cmsDocument table in SQL CE database, I can query other tables but this gives me error, and it says that "Unable to cast object of type 'System.DBNull' to type 'System.String'.". I also found out that cmsDocumentType table query is also a problem. How will I fix this?
And another issue is the content, document type and template I created previously are gone and just the old content is available. I renamed the main node in umbraco 6.16 site and added new nodes , saved and published. Now all new contents are lost.
I think these two issues are linked. I appreciate any suggestion.
I just found out that after there is any change in the content, the whole website should be refreshed in the WebMatrix. Otherwise, all the changes will be disappeared when the project is closed.

MVC3 Entity Connection string disappearing

I am having a very frustrating problem with my current project. It is continually losing the connection string binding for Entity models.
I have multiple models for different databases in separate areas and was having no problems. Suddenly now whenever I try to update from the database I get the connection string setup prompt. I select for it to add it to the Web.config with the password but it doesn't ever pick it up there again. They all are still in the web config but it just doesn't see them.
If I remove all the connection strings from the config file it will write the new one there. Then when I try to set up a Stored procedure/Function Import, I still get the statement in the lower box:
No database connection has been configured for this model.
I have tried rebuilding the project and creating the models again from scratch and that works for a while. When I try and bring the project in under Perforce source control, it winds up getting re-corrupted & the connection string goes away. It affects all of my models too.
I am also using EF 4.x DbContext Generator to create context files. They work fine. I am also able to run the application and it connects to the database just fine and returns data. No issues there. I am just unable to update Entity Complex types from the DB or import any more stored procedures.
An even weirder occurrence was that I opened a broken project from a different directory then opened an uncorrupted copy it instantly became broken also. Contagious!
Any thoughts on where to look into to see why this is happening? Has anyone else had this issue?
I seem to have found where the issue is coming from.
I seem to have a bad value somewhere in my web.config which causes the issue. Here is the work around I found did the trick and showed it's the config:
When the binding breaks, I closed the project then swapped out the web.config with one from a good build which was missing a couple keys but worked well enough to bind.
I reopen the the solution and the "No database connection..." error goes away.
Then while the solution is still open I re-swap the web.config back in and it still works.
This is far from optimal but I can work until I figure out the bad value via doing some compares.
I will comment on this again once I determine the exact issue.

MVC Code First Connection String. I changed it. How do I reinitialize the database?

I mean I was using a .SDF file but then had issues getting that to work with my host. So then I went back to the SQL DB I already have but I noticed that when I go to the default MVC 4 index page it is looking for that entity that I already created when I used the original DB.. but this table does not exist with the new SQL DB I switched to..
I already verified that is is pointing to the new DB buy setting the connection string in the constructer.
How do I tell the code to 'RE CREATE THE TABLE' before trying to use it ?
If I understand your question correctly, you're looking for something like Entity Framework Migrations: http://www.hanselman.com/blog/EntityFrameworkCodeFirstMigrationsAlphaNuGetPackageOfTheWeek10.aspx

Problems with Characterset when using DB2 SYSPROC.ADMIN_CMD for database import

I am running a Java Application that transfers the files I need to import to the server the DB2 is on. Then the Java Application creates a JDBC Connection to the database and runs:
CALL SYSPROC.ADMIN_CMD('import from <filename> of del modified by decpt, coldel; messages on server inert into <view>')
The problem I have seems somehow conencted to the charset of either the database of the user the database uses to import the files (using the admin_cmd stored procedure). That problem is:
"Umlaute", like ä,ö,ü get messed up by this import. I had this sort of problem in the past and solution always was to set the LC_CTYPE of the user importing the data to de_DE.iso88591
What I already ruled out as the source of the problem:
- The file transfer to the database server. (Umlaute are still ok after that)
- The JDBC Connection (I simply inserted a line through the sql command instead of reading from a file)
The thing is I don't now what user DB2 uses to import files through ADMIN_CMD. And I also don't believe it could somehow be connected to the DB2 settings, since with every other way of inserting,loading ... data into it, everthing works fine.
And yes, I need to use ADMIN_CMD. The DB2 Command Line Tool is a performance nightmare ..
The best approach (for sanity):
Create all databases as UTF-8
Make sure all operating system locales are UTF-8
Get rid of all applications that don't handle their data as UTF-8
Slaughter every developer and vendor not adhering to UTF-8. Repeat and rinse until 100% completed.
DB2 indeed attempts to be smart and convert your input data for you (the import command basically pipes your data into insert clauses - which always get handled like that). The link I gave will outline the basic principle, and give you a few commands to try out. Also, there is official explanation to the similar. According it you could attempt setting the environment variable db2codepage to correspond with your delimited data files, and that should help. Also, the IXF format exports might work better since they have encoding related information attached in every file.
Thanks for your response.
I finally fixed the issue by adding a
MODIFIED BY CODEPAGE=1252
to my JDBC - ADMIN_CMD Import Command. This seems to override any codepage settings the db was using before. It also appears the default codepage of the database didn't matter, since it is set to 1252. The only thing I can think of right now for being the reason for all this could be a linux setting DB2 uses when importing through ADMIN_CMD.

Resources