4

so currently, I have after a fair amount of trouble, managed to get my ASP.NET website hosted on an windows EC2 instance with IIS and MSQL SERVER 2008 r2. However, the website is unable to access the database because the connection string is set to the directory LOCALHOST\SQLEXPRESS where i was hosting the database on my own computer. So I copied the entire database over to the EC2 instance. Usually I generate a new connection string by using visual studio's connect to datasource but seeing as there is no visual studio on my ec2 instance, I cannot use that facility to generate the new string. the name on the EC2 server is WIN-B4PF9V1I0OJ if it's any help.

the connection string in the webconfig file looks like this :

<connectionStrings>
    <add name="YubiDBEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=LOCALHOST\SQLEXPRESS;initial catalog=YubiDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    <add name="YubiDBConnectionString" connectionString="Data Source=LOCALHOST\SQLEXPRESS;Initial Catalog=YubiDB;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />
  </connectionStrings>
user3506473
  • 69
  • 1
  • 5
  • Whats wrong with `connectionString="Data Source=WIN-B4PF9V1I0OJ;Initial Catalog=Your Database; Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"`? – Izzy Mar 11 '15 at 16:41
  • Just remeber you will need to provide username and password unless you've set it up to connect using windows account credentials – Izzy Mar 11 '15 at 16:49

1 Answers1

12

It's actually pretty easy to get a GUI to create a connection string on any Windows computer, even without VS.

Create an empty text file, but name it with a ".udl" extension. The file name does not matter--I use db.udl. Once the file is created, double-click on it and you will see a GUI open up to guide you building your connection string. Once done, open the udl file up in your favorite text editor and scrape out the connection string.

Jim
  • 2,034
  • 1
  • 22
  • 43
  • Wow!!! I never knew about this. Like they say you learn something new everyday +1 from me – Izzy Mar 11 '15 at 16:53
  • @Izzy; Yeah, most don't... It is one of those little known secrets. I was taught this back on XP. I just tired it on W8.1 and it still works. I'm not even sure what the original intent of the "udl" file is supposed to be--I just use it for hacking together connection strings. – Jim Mar 11 '15 at 16:56
  • i see it generates an oledb connection string. thanks very much! can i just replace the existing strings with this then? – user3506473 Mar 11 '15 at 17:01
  • @user3506473; That might be, but it also may be dependent on the Provider you picked, which is the first tab. This tool always opens to the second tab. That said, it is usually close enough for me and anything else is just minor tweaks. – Jim Mar 11 '15 at 17:08
  • +1 I wasted nearly an hour trying to build a connection string and it kept giving errors. Your answer is very helpful. – Reddy Lutonadio Feb 10 '21 at 10:46