views:

645

answers:

4

Hi, i am a newbie programmer, and i have a problem with sqldatasource. In my project, i have a database called "KFS". I have a gridview and sqldatasource as gridview's datasource. I have a connection string like that:

"KFSConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=KFS;Integrated Security=True" providerName="System.Data.SqlClient"

This is working in VS2008 but when i load this on my website, it doesn't work. How should i change my connection string?

+1  A: 

When running in Visual Studio you are able to connect to a database on your local system. When you publish the web site to a web server, there is no local database for it to connect to. You'll need to put your database on a SQL server (or use local MDF file in App_Data) and adjust your connection string accordingly.

The connection to a local file in the application would look something like this:

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf;
    Database=dbname;Trusted_Connection=Yes;

See this reference for some various connection string options.

Here's a reference on how to access data in ASP.NET and VS2005. I think this should still apply, at least with respect to the connection strings.

tvanfosson
I changed like this, but it isn't still working:(connectionString="Server=.\SQLExpress;AttachDbFilename=App_Data\KFS.mdf;Database=KFS;Trusted_Connection=Yes" providerName="System.Data.SqlClient"
Mehmet Kaleli
I've added a reference on how to access data in ASP.NET and VS2005. It should still be applicable to what you are doing.
tvanfosson
+1  A: 

The '.\sqlexpress' in the Data Source property of your connection string is telling the application to connect to a SQL Server on the same machine. If your web server is on a different computer you need to replace the '.' with the name of your computer. The \sqlexpress portion is the name of the SQL Server instance which you shouldn't need to change.

You also want to make sure that your SQL Server allows remote connections. By default I don't think it does. You can use the SQL Server Surface Area Configuration tool to change the remote connnection permissions. The SAC tool should have been installed when you installed SQL Server under the Microsoft SQL Server 200x --> Configuration Tools folder in your Start Menu. Have a look at the Surface Area Configuration for Services and Connnections and in there find the Remote Connections item.

TLiebe
A: 

I'd guess that either (or both) "Data Source" and/or the "integrated security" is incorrect. Your connection string is saying that the database is on the same server as the web server (signified by ".") and that the database is MSSQL Express, using a named instance (signified by .\"express") "integrated security=true" means that the account running your web server's aspx pages should be used to try to access the database. In my experience neither of these things are likely on a 3rd party hosting site. The database is mostly likely on a different server, and has specific credentials (username/password). I suggest calling your hosting provider's support or examining any activation emails you would have gotten from them.

Then again, you could be talking about your "website" meaning IIS on your development box (as opposed to vs2008's builtin server), and I may have wasted several minutes typing this. :D

-Oisin

x0n
A: 

IT SHOULD WORK IN LOCAL ,BUT WHEN U UPLOAD IN SERVER U SHOULD POST SERVER IP ADDRESS

THANKS SEZHI

sezhi
All caps is very poor here.
Nick