title: VBA Connection from Excel 2010 to SQL Server 2008
body: <p>i'm pretty new to SQL and VBA, so please forgive any audacity the code below may contain. I am working with code written in Excel's VBA. Eventually, the data from the user form in excel will be entered into a SQL database I have created using SQL Server 2008. Right now, I am just trying to open the connection to the SQL database and enter hard coded values into the db. Unfortunately, this has been much more of a challenge than I expected. I have tried playing around with the connection string a few different ways but have had no luck. When the form runs, I get no errors and I can see the data was added into the appropriate excel worksheet (but no changes in the SQL DB). I can see the db on SQL Server Management Studio and add rows from there, but I am unable to add a row to the db via this code. The db is protected solely by windows authentication. Any help would be greatly appreciated. </p>
  
  <pre><code>Sub ConnectSqlServer()
  '********SPC DATABASE CONNECTION**********************
  'write slurry information to database
  'spc_date, mix_type, slurry_lot_num, mixer_num, shift, oper
  
  Dim conn As ADODB.Connection
  Dim rs As ADODB.Recordset
  Dim sConnString As String
  
  'Create connection string
  sConnString = "Provider=sqloledb; Server=SERV; Database=db; Trusted_Connection=True;"
  
  'Create the Connection and Recordset objects
  Set oConn = New ADODB.Connection
  Set rs = New ADODB.Recordset
  
  'Open connection and execute
  conn.Open sConnString
  Set rs = conn.Execute("INSERT INTO TBL (col1, col2) VALUES ('val', 'val');")
  
  'Clean up
  If CBool(conn.State And adStateOpen) Then conn.Close
  Set conn = Nothing
  Set rs = Nothing
  
  End Sub
  </code></pre>