2

I'm creating a Windows service that accesses tables in a SQL Server database.

How would I go about streamlining this, so I don't have to hardcode the username and password in the connection string?

It only needs read and write and query notifications (I don't know if there are explicit rights for that).

What are my options?

And which would be the best solution?

Thanks in advance

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
VisualBean
  • 4,908
  • 2
  • 28
  • 57

1 Answers1

2

Consider using Windows authentication to avoid a username and password in the connection string at all.

Here are a couple examples from an older MSDN article:

<connectionStrings>
  <add name="MyDbConn1" 
      connectionString="Server=MyServer;Database=MyDb;Trusted_Connection=Yes;"/>
  <add name="MyDbConn2" 
      connectionString="Initial Catalog=MyDb;Data Source=MyServer;Integrated Security=SSPI;"/>
</connectionStrings>

What the connecting SQL Server login and mapped database user can do - e.g. create and delete tables - is just a matter of the roles you assign and permissions you grant using SQL Server's security mechanisms.

Community
  • 1
  • 1
J0e3gan
  • 8,740
  • 10
  • 53
  • 80