title: SQLAlchemy/pandas to_sql for SQLServer -- CREATE TABLE in master db
body: <p>Using MSSQL (version 2012), I am using SQLAlchemy and pandas (on Python 2.7) to insert rows into a SQL Server table.</p>
  
  <p>After trying pymssql and pyodbc with a specific server string, I am trying an odbc name:</p>
  
  <pre><code>import sqlalchemy, pyodbc, pandas as pd
  
  engine = sqlalchemy.create_engine("mssql+pyodbc://mssqlodbc")
  sqlstring = "EXEC getfoo"
  dbdataframe = pd.read_sql(sqlstring, engine)
  </code></pre>
  
  <p>This part works great and worked with the other methods (pymssql, etc). However, the pandas to_sql method doesn't work.</p>
  
  <p><code>finaloutput.to_sql("MyDB.dbo.Loader_foo",engine,if_exists="append",chunksize="10000")</code></p>
  
  <p>With this statement, I get a consistent error that pandas is trying to do a CREATE TABLE in the sql server Master db, which it is not permisioned for.</p>
  
  <p>How do I get pandas/SQLAlchemy/pyodbc to point to the correct mssql database? The to_sql method seems to ignore whatever I put in engine connect string (although the read_sql method seems to pick it up just fine.</p>