Uploading Website with Visual Basic Inbuilt .mdf Database in VB.Net (Aspx) - vb.net

I am creating a website to have a database with it (i.e. Upload the website with the App_Data folder that has Database.mdf in it).
But it cannot connect the attached database using (web.config file)
It works on localhost but it does not work when uploaded, can anyone help me?
**
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</connectionStrings>
<appSettings>
<add key="ConnectionString" value="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True" />
</appSettings>
**

The attribute 'Data Source' in ConnectionString notifies SQL Server instance you are using. On Localhost, it will work fine because you have a actual SQL service running there. But when you upload the Site to web server, you must have a SQL server instance running there.
To achieve that, you have to upload your database to server, then you will get server username, password. Now change the connectionstring according to that in web.config and your application will work fine. No need to keep .mdf in App_Data folder.

Related

VB.net app doesn't update the connection string after changing the app.config file

I have done a windows application using vb.net and have set the connection string to be read from the app.config file. everything works fine, but when I try to change the connection string in the app.config file ( for example to change the database location) the application can't find the database anymore.
is there a problem or am I missing something related the connection strings. thank you
If you use MS Access database, you have to specify every database.
`<connectionStrings>`
<add name="ConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\DatabaseName1.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
</connectionStrings>
<connectionStrings>
<add name="ConnectionString"
connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\DatabaseName2.mdb;Persist Security Info=True"
providerName="System.Data.OleDb" />
Also, there is a specific path to every database. The best way is to use the asp.net database folder App_Data and put all databases in this folder.

Database shows up in App_Data & not in SQL Server

Does anyone know why my database won't show up in SQL Server, but will show up in App_Data? I did code first migration and update the database but still can't see it. Please help
I try changing the connection and it did not work
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-Rentals.mdf;Initial Catalog=aspnet-Rentals;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
No database shows up

SQL Server Express is not installed on your system

When I try to open code for an existing ASP.NET MVC application in Visual Studio 2015, it shows a warning like
In that application, there is a connection string:
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />'
I have SQL Server 2012 installed in my system.
Pretty easy:
Attach that .mdf file that's being referenced in the original connection string to your SQL Server 2012 instance
Change the connection string to the new situation - something like:
<add name="ApplicationServices"
connectionString="data source=.;initial catalog=aspnetdb;Integrated Security=SSPI;"
providerName="System.Data.SqlClient" />
Just simply ignore that VS warnings if it ever occurs again ....
The reason for the warning is the AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true setting of the original connection string; this approach (which I DO NOT recommend at all) only works with the Express edition of SQL Server - not with any other editions.

Failed login for user

I'm developing a website for sharepoint using asp.net, it is connected to a database. In visual studio server explorer, the database is accessible using a new sql user I created. I granted sysadmin permissions to that user. However, when I deploy the site and run it, it gives me this error 'login failed for user'.
The sql server is configured to allow mixed authentications. I restarted the server, I played with the user permissions but nothing ever changed.
The connection string I got it from server explorer which I'm sure it is correct:
Data Source=servertest;Initial Catalog=qDB;User ID=me2;Password=***********"
What should I do? I've tried every possible solution I found on google and I ended up here.
Try like this by editing your connection string:-
Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;
I too had same scenario this worked for me
<connectionStrings>
<add name="connectionstring" connectionString="Data Source=XYZ\SHAREPOINT;Initial Catalog=DBName;Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
You can Use connection string like this
<appSettings>
<add key="KhadamatConnectionString"
value="Server=[copy name from Your ServerName of SSMS];Database=AcaService;uid=admin;pwd=mypass;" />
</appSettings>
or
<connectionStrings>
<add name="KhadamatConnectionString" connectionString="Data Source=[copy name from Your ServerName of SSMS];Initial Catalog=AcaService;User ID=admin;Password=mypass;" providerName="System.Data.SqlClient"/>
</connectionStrings>

ELMAH with IIS6.0 and SQL Server 2005

On production I have ELMAH configured so that the errors are logged into a SQL Server 2005 database created specially for ELMAH. The sites run on IIS6.0 web server.
ELMAH is able to send emails for the errors, but nothing is getting logged into the SQL Server database. The connection is a trusted connection and I have
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah"/> in section group
<errorLog type="Elmah.SqlErrorLog, Elmah" connectionStringName="Elmah.Sql" applicationName="VBCPortal"/> under elmah
<add name="Elmah.Sql" connectionString="Data Source=(local);Initial Catalog=ELMAH;Trusted_Connection=True" /> in connectionStrings
in my web.config file.
Any idea why the errors are not getting logged into the database?
Most likely cause is the aspnet user account does not have permission to the database.