title: VBA connection string to SQL Server Express 2017
body: <p>My environment is Windows 10 (PCA), SQL Server Express 2017, and I'm using VBA.</p>
  
  <p>I'm trying to do something really simple. Since I can't use SQL Server CE, I'm using SQL Server Express 2017. I simply want to create an MDF file I can use on another Windows 10 computer (PCB) that is also running SQL Server Express 2017 and have my VBA code open up the database.</p>
  
  <p>So I went about this task by creating a database in SQL Server Mgt Studio. It put the .mdf file in "C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA".</p>
  
  <p>If I stop the service "SQL Server (MSSQLSERVER)", I can copy out the .mdf and log file to another location. Eventually I want to access the file from a remote computer, but just trying to get this seemingly simple task done.</p>
  
  <p>The problem is I can't open up the file using ADODB on another computer, even after I copy it from PCA to PCB. Heck, I can't even open it up on the same computer I created it on (PCA) using the VBA code below! Maybe it's my connection string?</p>
  
  <p>Everyone can have access to it, and I plan on accessing it through password and also encrypting the file,  but for now I'll take just opening it!</p>
  
  <p>I've tried all these connection strings, but I'm a bit confused on password protecting the file in SSE?</p>
  
  <pre><code>Set dbConn = CreateObject("ADODB.Connection")
  dbConn.Mode = adModeShareDenyNone
  dbConn.CursorLocation = adUseServer
  
  sDBFile = "\\PCB\c$\programdata\company\product\test.mdf"
  
  '   SQL Express 2017
  sConnectionString = "Driver={SQL Server};Server=M10;Database=test;Trusted_Connection=True;"
  sConnectionString = "Driver={SQL Server};Server=M10;AttachDbFilename=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Database=test;Trusted_Connection=Yes;Initial Catalog=test;User Instance=True; "
  sConnectionString = "Driver={SQL Server};Server=M10;AttachDbFilename=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Trusted_Connection=Yes;"
  sConnectionString = "Driver={SQL Server};Server=M10;Initial Catalog=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Trusted_Connection=yes;"
  sConnectionString = "Driver={SQL Server};Server=M10;Initial Catalog=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Trusted_Connection=Yes;User ID=domain\user1;Password=password;Database=" &amp; Chr$(34) &amp; Chr$(34) &amp; ";"
  sConnectionString = "Driver={SQL Server};Server=M10;Initial Catalog=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Trusted_Connection=Yes;User ID=domain\user1;Password=password;Database=test;"
  sConnectionString = "Driver={SQL Server};Server=M10;Initial Catalog=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";User ID=domain\user1;Password=password;"
  
  sConnectionString = "Driver={SQL Server};Data Source=M10;Initial Catalog=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Integrated Security=True;Pooling=False"
  sConnectionString = "Data Source=M10;Initial Catalog=test.sdf;Integrated Security=True;Pooling=False"
  
  sConnectionString = "Driver={SQL Server};Data Source=M10;AttachDbFilename=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Initial Catalog=test;Integrated Security=True;"
  sConnectionString = "Driver={SQL Server};Server=M10;AttachDbFilename=" &amp; Chr$(34) &amp; sDBFile &amp; Chr$(34) &amp; ";Initial Catalog=test;Integrated Security=True;Trusted_Connection=Yes;"
  sConnectionString = "Data Source=M10;Initial Catalog=test;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
  
  dbConn.ConnectionString = sConnectionString
  
  dbConn.Open
  </code></pre>