Deployment of SQL Server Express database fails - asp.net

I have to deploy ASP.Net application with remote database connection in IIS server.
Deployment has worked fine without database. And I was able to run that application on the IIS server.
Coming to the application with remote database I have given the connection string in C# code. And it is connected.
My web.config has thsi connection string :
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
I have replaced that with my database connection credentials as follows:
<configuration>
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=RemoteHost,1433;Initial Catalog=DBNAME;user Id=MyUserId;Password=MyPassword"
providerName="System.Data.SqlClient" />
</connectionStrings>
In Package/Publish options I have selected (Import from web.config) and deployed that. Then I got the following error:
Web deployment task failed.(Object of type 'dbFullSql' and path 'Data
"Data Source=RemoteHost,1433;Initial Catalog=DBNAME;user
Id=MyUserId;Password=MyPassword" cannot be created.)
Object of type 'dbFullSql' and path "Data Source=RemoteHost,1433;Initial Catalog=DBNAME;user
Id=MyUserId;Password=MyPassword" cannot be created.
The source is invalid.
Script failed for Database 'DBNAME'.
Script failed for Database 'DBNAME'.
Index was outside the bounds of the array.
I am new to ASP.Net. Anybody please help me.
Thank you in advance

I think you didn't configure Web deployment package correct you can do that right Click on Project ,Select Properties and go to package/Publish SQL
I have add link for Walkthrough: Deploying a Web Application Project Using a Web Deployment Package (Part 1 of 4) for VS2010
http://msdn.microsoft.com/en-us/library/dd483479(v=vs.100).aspx

Related

ASP.NET VB change db connection on web forms framework

I have created an instance of ASP.NET Web Forms in my Microsoft Visual Studio. By default the program generates user login page and registration which are linked to the .mdb file.
I want to reconfigure the standard connection and link it to my instance of MSSQL 2012 SQLExpress server.
How can I do it?
Ok so I will give some direction and link you to a page.
First let me ask you this the connection you are using presently is it in a web.config file. If so this is where you will change the server/instance and database/catalog name.
Web.Config modification for SQL Server Instance
or this link
Web Config modification for SQL Express 2
So if you in the web.config file you should see something similar to this.
<ConnectionStrings>
<add name="" connectionString="Server=(localhost)\SqlExpress;Max Pool Size=300;Initial Catalog=database;User ID=username;Password=password;" providerName="System.Data.SqlClient"/>
</Connectionstrings>
or
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source= (LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\database.mdf;Initial Catalog=database;Integrated Security=True" providerName="System.Data.SqlClient" />
you need to change the follow:
Server or Data Source
and
Initial Catalog or AttachDbFilename
Now your credentials you may use any username and password that has access to the sql server express instance.
I hope this helps.

connection string problems in asp.net, sql server

I have created a database on my host using SQL server management studio and have uploaded my website, App_Code and App_Data folders. My connection string is as follows:
<connectionStrings>
<add name="abc"
connectionString="Data Source=serverNane;
Initial Catalog=dbname;
Integrated Security=false;
User ID=user;
Password=pwd"
providerName="System.Data.SqlClient" />
</connectionStrings>
On using my login page, i got an error as i had not added customErrors to my web.config file. After adding customErrors and a default errors page, i can not understand what error has occurred as the stack trace is not visible. Is there something wrong with my connection string?

How to reference to the database that resides on another server in the webconfig file?

I am a new developer and this is my first time to deal with two IIS servers. My company has two servers; Production Server and Testing Server. They are using the testing server for storing /hosting the databases and the Production Server for hosting the applications. All the applications are developed in ASP.NET. Now, for the web-based application that I am developing; I have to put the database in the Testing Server and the application in the Production Server,
so how can I reference the database in the web.config file?
What I have in my web.config file now is the following:
<connectionStrings>
<add name="testConnectionString" connectionString="Data Source=localhost\sqlexpress;Initial Catalog=psspTest;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
I have that because the database resides in the same server with the application. Therefore, how will I be able to reference when I put it in the Testing Server?
Let's say your testing server is called testsrv and the database resides on the
SQL Server Express instance, you simply change your config to:
<connectionStrings>
<add name="testConnectionString"
connectionString="Data Source=testsrv\sqlexpress;Initial Catalog=psspTest;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>

web.config and membership

I have an Runtime error when I'm trying to perform login action or create user action on published website.
I have an ASPNETDB.MDF in appData folder, that created from ASP.NET Configuration.
I created new database in hosting, exported from ASPNETDB.MDF to a new database. I changed connection string.
Localy it work perfect, even with new connection string, but after i publish it i have an Runtime error.
I'm using asp login control and CreateUserWizard.
BTW, i've created some GridView and SqlDataSource to show all users, and it works.. But login and createWizard are not.
web.config
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<compilation debug="false" targetFramework="4.0" />
</system.web>
</configuration>
BTW, i tryed to add membership provider to web.config and it didn't work even localy ))
UPD:
The error
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Well for starters you could add the following to your web.config:
<configuration>
<system.web>
<customErrors mode="off"></customErrors>
</system.web>
</configuration>
This should allow you to get a more detailed error message about what is wrong. See if that get's you started down the right path. It should at least provide more information about what might be wrong.
Update - try this in your web.config:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="LocalSqlServer" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
<add name="ConnectionString" connectionString="Server=mssql3322.dotnet-host.com;Database=aspnetdb3;Uid=SomeUserNAme;Password=SomePassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Update - That worked! Here is a short explanation why:
By default the ASP membership classes use the connection string LocalSqlServer. The reason the code worked on your local machine is because the connection LocalSqlServer is defined in a machine level config file to point to the local sql database. When you published it the SqlDataSource/GridView worked because it was pulling the connection named ConnectionString that pointed to the correct server. However ASP membership was still trying to connect to the LocalSqlServer connection. The above config just ignores the machine level LocalSqlServer connection and defines it's own (and it leaves the ConnectionString one in place so that the GridView continues to function).

Whats wrong in this ASP.Net web.config connection string?

i have attached database file C324040_volvo.mdf to my mssql2005 management studio whose name in mssql2005 management studio is ASPNETDB
but page doesn't found the database....and the site doesn't load
i m testing my site in my local computer ...
<connectionStrings>
<add name="connectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\C324040_volvo.mdf;Database=ASPNETDB;Integrated Security=True;User Instance=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
Page searches for a log time ...
If you've already added it to SQL Server then you shouldn't need
AttachDbFilename=C:\C324040_volvo.mdf
If it isn't already attached, then SQL probably doesn't have rights to the root of C: and you should move it.

Resources