Showing posts with label connecting. Show all posts
Showing posts with label connecting. Show all posts

Thursday, March 22, 2012

Cannot open user default database. Login failed.

Hi,

I got this application system having SQLExpress as database (ABCSystem.mdf). I'm connecting to the database thru connection string specifying database path in App.config.

At the same time, I got two paths for the mdf files. The first one is the path for my database project while the second one is the path to conduct testing. (This means that I got identical ABCSystem.mdf in two paths)

1) C:\Program Files\Company ABC\ABCDatabaseProject\

2) C:\Program Files\Company ABC Limited\ABCSystem\Database\

In my development machine, I can run my application where database path is testing path (number 2).

When I tried to copy the ABCSystem.mdf and ABCSystem_log.LDF and my application program files to another PC to test, I got the subject error message. (note that I copy program files under directory "C:\Program Files\Company ABC Limited\ABCSystem\" and mdf files under "C:\Program Files\Company ABC Limited\ABCSystem\Database\")

I try to edit path from database testing path to database project path in app.config, run the application, and notice that it is running OK.

What seems to cause the problem? Coz I need the database in the testing path which is "C:\Program Files\Company ABC Limited\ABCSystem\Database\" AND NOT "C:\Program Files\Company ABC\ABCDatabaseProject\".

Thanks alot for your kind attention.

Try this first, and then check your string accordingly:

http://msdn2.microsoft.com/en-us/library/ms345332.aspx

Buck Woody

|||I'm having this identical issue with an ODBC connection.
After wasting hours, I realized I only get the error when I try to change database name. (e.g. from a development to a production server). Based upon everything I've tried, I determined you CANNOT change server name in a Crystal report programmatically as in the Crystal sample code. It may be a possible to change servers if using a command based report (explicit SQL query), but our reports all use tables so a trial would be irrelevant.

Cannot open user default database. Login failed.

Hi,

I got this application system having SQLExpress as database (ABCSystem.mdf). I'm connecting to the database thru connection string specifying database path in App.config.

At the same time, I got two paths for the mdf files. The first one is the path for my database project while the second one is the path to conduct testing. (This means that I got identical ABCSystem.mdf in two paths)

1) C:\Program Files\Company ABC\ABCDatabaseProject\

2) C:\Program Files\Company ABC Limited\ABCSystem\Database\

In my development machine, I can run my application where database path is testing path (number 2).

When I tried to copy the ABCSystem.mdf and ABCSystem_log.LDF and my application program files to another PC to test, I got the subject error message. (note that I copy program files under directory "C:\Program Files\Company ABC Limited\ABCSystem\" and mdf files under "C:\Program Files\Company ABC Limited\ABCSystem\Database\")

I try to edit path from database testing path to database project path in app.config, run the application, and notice that it is running OK.

What seems to cause the problem? Coz I need the database in the testing path which is "C:\Program Files\Company ABC Limited\ABCSystem\Database\" AND NOT "C:\Program Files\Company ABC\ABCDatabaseProject\".

Thanks alot for your kind attention.

Try this first, and then check your string accordingly:

http://msdn2.microsoft.com/en-us/library/ms345332.aspx

Buck Woody

|||I'm having this identical issue with an ODBC connection.
After wasting hours, I realized I only get the error when I try to change database name. (e.g. from a development to a production server). Based upon everything I've tried, I determined you CANNOT change server name in a Crystal report programmatically as in the Crystal sample code. It may be a possible to change servers if using a command based report (explicit SQL query), but our reports all use tables so a trial would be irrelevant.

Sunday, March 11, 2012

cannot login

Well, I've tried every suggestion by helpful people in connecting to a database I created, to no avail.

I created a db, called, nodes10.mdf.
Test connection works.
Right now I get:

Cannot open database "nodes10" requested by the login. The login failed.
Login failed for user '<server>\<user>'.
Before you call me on my syntax, the problem is with logging in , not my insertString.

code:

SqlConnection conn = new SqlConnection("Data Source=NORBY11\\SQLExpress;Integrated Security=SSPI;Initial Catalog=nodes10;Connect Timeout=30;User Instance=True");

string ndeText=numberNode.Text;
string insertString = @."INSERT INTO table1(nodenames) VALUES(ndeText)";
SqlCommand cmd = new SqlCommand(insertString,conn);
//cmd.CommandText = insertString;

comboBox1.Items.Add(numberNode.Text);

try
{

conn.Open();

cmd.ExecuteNonQuery();

Also, are you supposed to be able to see my database in sqlexpress? like when you open up sqlserver config?

And why does my connection icon have a red x after I start my program?

Here are a couple questions:

Are you logged onto NORBY11 when you run this code? User Instances only support local connections.|||

yes, I'm logged into norby11.
So I've tried to use the attachdbfile syntax but the compiler doesn't like it. What should it be?
If I cut and paste the attachdb stuff from the properties window for the db, is that the correct way, because the compiler sure ain't buying it!

In the app.config file it says:

AttachDbFilename=|DataDirectory|\nodes10.mdf

HUH?|||Also, I don't know what this implies:

table1 (or whatever table number I'm fooling with at the time) is invalid object.
I got this one time while fooling around with different things in the connection string.
Does that mean no connection was made to the database, or is it that the table wasn't found, or that the table should exist someplace on my hard drive or ?|||

The AttachDBFilename syntax supports the use of |DataDirectory| when the database is in the same directory as the application. (Bold 'cause it's important.) If you put your database in a different directory, then you need to specify the full path to the database file.

Just for grins, is this a WinForm app or an ASP.NET web site your working in?

I got a small alarm bell when you mentioned copying the connection string out of the property box. Is this database embedded into your application? If the database is embedded into your application the connection string is automatically managed by VS so you don't need to open a connection manually.

If this is an ASP.NET application the issue could be with permissions since the user loging in is probably the ASP.NET user rather than your own user account. I'm not much of a web guy, but if this is the case, I can point you to a whole set of forums targeted at developing web applications on SQL Express.

Regards,

Mike Wachal
SQL Express team

-
Check out my tips for getting your answer faster and how to ask a good question: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=307712&SiteID=1

|||It's a WinForms app.

I believe it's called an embedded db. I created the database from within visual studio.

If I don't need to open the connection, why do I get an error on the line cmd.ExecuteNonQuery regarding opening a connection? --'connection property has not been initialized?'|||I have a couple more questions, if I could.

When I create a new data connection, then create a table within that db, should a table exist in the directory where my program is located? I notice in programs that I tried in VC#2005 book that tables appear in the directory. Of course, those programs didn't work either, and I can't connect to the db in them, or I get invalid object when I run them.

What a cluster.|||

Hi zenguitar,

As far as the need to connect, I'm talking about using DataSets in VS 2005. You'll be much better information about these by reading the VS documentation (http://msdn2.microsoft.com) and by hanging out in the .NET Data Access forum at http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=45&SiteID=1, but I'll try to give you the basics here.

There are a number of different ways to create a DataSet in VS, including adding a database into your project and creating a new DataSource from an existing database. The net of these actions, is that you end up in the DataSet Wizard and you can pick database objects to be exposed in the DataSet.

Once you have a DataSet, you can just drag items from the Data Sources pane onto your WinForm and have VS do all the magic of creating the objects needed to bind your data to your controls. VS also creates additional items such as a BindingSource and a TableAdapter and BindingNavigator to make you life easier. Using a DataSet also stores a ConnectionString for your database in the application settings and uses that connection string to automatically connect to your database to retreive or updated data based on your code against the DataSet. Exactly how the connection string is formed depneds on how you create the DataSet.

If you're goal is to place data bound controls on your forms, I suggest that explore the use of the DataSet as the way to do this since a bunch of the functionality is baked into VS for you.

Performing an operation such as running a Command object is still going to require that you make the connection yourself. Now you can write your connection string manually, you could store a connection string in the applicaiton settings or you could "steal" connection string from an existing Data Source that is already stored in your database. It's all really up to what your needs are.

None of this really gets to why you are getting a failed login error though. My guess is that you've still got a technology mix up between the user instance and the main instance and which one you're actually using.

Is your database nodes10 actually attached to SQL Express already? Do you access it via any other tools? (Which ones?) Does your user account actually have a Login on the server and a User account in the database?

As far as embedded databases, one way to get an embedded database is to create it via the Projects | Add New Items menu. One of the options is SQL Database, and this will actually put a database file directly in your project directory. It will also show up in Solution Explorer. If you don't see the database in Solution Explorer, then it isn't embedded. The whole idea of an embedded database is that the .mdf and .ldf files travel with the applicaiton and are attached at runtime to a User Instance. These are not suitable for an application that requires multi-user access becasue User Instances only support single user, local only access.

If you create a database using Server Explorer, it is not embedded, rather it is attached the main instance of the server and placed in the Data directory for the server. This is the way to go for multi-user access databases.

You can create DataSets against either of these databases.

As far as your final questions:

Tables don't exist independently of the database file. When you create a new table, it is stored in the database file in what ever directory that database was created in. Where the database resides is dependent on how it was created in VS as I've described above.

Sunday, February 12, 2012

Cannot generate SSPI context

Hi,
Im having trouble connecting to the SQL2005 default instance installed on
one of my sql servers within my domain. I have a second SQL2005 server that
I
can connect to just fine. Both are in the same OU.
This particular server, I can connect to AS2005, but not to SQL2005. I keep
getting the 'Cannot generate SSPI context. (.Net SqlClient Data Provider)'
error. I've not changed anything in terms of settings on my PC, nor have any
settings been changed on the SQL server, though I was able to connect to
SQL2005 for this server last week. Something obviously has changed, but I
have no idea where to look. One of the other SysAdmins has no problems
connecting to the database.
I'm hoping this is just something simple to fix.
regards,
AnatoliAll the below is happening while I'm attempting to connect remotely from my
XP SP2 pc using SSMS.
Further to this, I've found that I can connect to the server in question
remotely using the SA account. I can also, connect to SQL2005 locally with m
y
network account from within an RDP session.
"Anatoli" wrote:

> Hi,
> Im having trouble connecting to the SQL2005 default instance installed on
> one of my sql servers within my domain. I have a second SQL2005 server tha
t I
> can connect to just fine. Both are in the same OU.
> This particular server, I can connect to AS2005, but not to SQL2005. I kee
p
> getting the 'Cannot generate SSPI context. (.Net SqlClient Data Provider)'
> error. I've not changed anything in terms of settings on my PC, nor have a
ny
> settings been changed on the SQL server, though I was able to connect to
> SQL2005 for this server last week. Something obviously has changed, but I
> have no idea where to look. One of the other SysAdmins has no problems
> connecting to the database.
> I'm hoping this is just something simple to fix.
> regards,
> Anatoli|||Anatoli,
check these links.
http://support.microsoft.com/kb/811889/
http://msdn2.microsoft.com/en-us/library/ms191153.aspx
http://msdn2.microsoft.com/en-us/library/ms189585.aspx
Hope this helps
Markus|||Markus,
Thanks for your reply. From what I can tell, this problem is specific to my
domain account. That is that I can connect remotely to the SQL server using
the SA account, but I can't connect using my domain account. I tried using
another PC from which one of other admins was able to easily connect to
SQL2005. I don't use a roaming profile, and this was the first time I logged
onto that PC and still I got the same error. Again, when I logged in locally
to the SQL server I didn't have any problems SSMS connecting.
So from what I can tell, there aren't any setting issues on the SQL server
side nor are there any issues from my PC side as I'm able to connect to othe
r
instances of SQL 2005 with my domain account.
Are there any settings associated with the login to cause such an error?
"MarkusB" wrote:

> Anatoli,
> check these links.
> http://support.microsoft.com/kb/811889/
> http://msdn2.microsoft.com/en-us/library/ms191153.aspx
> http://msdn2.microsoft.com/en-us/library/ms189585.aspx
> Hope this helps
> Markus
>|||Turned out to be how the system guys upgraded the server to W2K3, SQL and AS
2005. They blew away the old sql server and installed W2K3, SQL/AS 2005, but
never removed the computer object out of AD. Used the SETSPN.exe utility
determine that there was more than one SPN for that particular server.
regards,
"Anatoli" wrote:
[vbcol=seagreen]
> Markus,
> Thanks for your reply. From what I can tell, this problem is specific to m
y
> domain account. That is that I can connect remotely to the SQL server usin
g
> the SA account, but I can't connect using my domain account. I tried using
> another PC from which one of other admins was able to easily connect to
> SQL2005. I don't use a roaming profile, and this was the first time I logg
ed
> onto that PC and still I got the same error. Again, when I logged in local
ly
> to the SQL server I didn't have any problems SSMS connecting.
> So from what I can tell, there aren't any setting issues on the SQL server
> side nor are there any issues from my PC side as I'm able to connect to ot
her
> instances of SQL 2005 with my domain account.
> Are there any settings associated with the login to cause such an error?
> "MarkusB" wrote:
>

Cannot generate SSPI context

Hi,
Im having trouble connecting to the SQL2005 default instance installed on
one of my sql servers within my domain. I have a second SQL2005 server that I
can connect to just fine. Both are in the same OU.
This particular server, I can connect to AS2005, but not to SQL2005. I keep
getting the 'Cannot generate SSPI context. (.Net SqlClient Data Provider)'
error. I've not changed anything in terms of settings on my PC, nor have any
settings been changed on the SQL server, though I was able to connect to
SQL2005 for this server last week. Something obviously has changed, but I
have no idea where to look. One of the other SysAdmins has no problems
connecting to the database.
I'm hoping this is just something simple to fix.
regards,
AnatoliAll the below is happening while I'm attempting to connect remotely from my
XP SP2 pc using SSMS.
Further to this, I've found that I can connect to the server in question
remotely using the SA account. I can also, connect to SQL2005 locally with my
network account from within an RDP session.
"Anatoli" wrote:
> Hi,
> Im having trouble connecting to the SQL2005 default instance installed on
> one of my sql servers within my domain. I have a second SQL2005 server that I
> can connect to just fine. Both are in the same OU.
> This particular server, I can connect to AS2005, but not to SQL2005. I keep
> getting the 'Cannot generate SSPI context. (.Net SqlClient Data Provider)'
> error. I've not changed anything in terms of settings on my PC, nor have any
> settings been changed on the SQL server, though I was able to connect to
> SQL2005 for this server last week. Something obviously has changed, but I
> have no idea where to look. One of the other SysAdmins has no problems
> connecting to the database.
> I'm hoping this is just something simple to fix.
> regards,
> Anatoli|||Anatoli,
check these links.
http://support.microsoft.com/kb/811889/
http://msdn2.microsoft.com/en-us/library/ms191153.aspx
http://msdn2.microsoft.com/en-us/library/ms189585.aspx
Hope this helps
Markus|||Markus,
Thanks for your reply. From what I can tell, this problem is specific to my
domain account. That is that I can connect remotely to the SQL server using
the SA account, but I can't connect using my domain account. I tried using
another PC from which one of other admins was able to easily connect to
SQL2005. I don't use a roaming profile, and this was the first time I logged
onto that PC and still I got the same error. Again, when I logged in locally
to the SQL server I didn't have any problems SSMS connecting.
So from what I can tell, there aren't any setting issues on the SQL server
side nor are there any issues from my PC side as I'm able to connect to other
instances of SQL 2005 with my domain account.
Are there any settings associated with the login to cause such an error?
"MarkusB" wrote:
> Anatoli,
> check these links.
> http://support.microsoft.com/kb/811889/
> http://msdn2.microsoft.com/en-us/library/ms191153.aspx
> http://msdn2.microsoft.com/en-us/library/ms189585.aspx
> Hope this helps
> Markus
>|||Turned out to be how the system guys upgraded the server to W2K3, SQL and AS
2005. They blew away the old sql server and installed W2K3, SQL/AS 2005, but
never removed the computer object out of AD. Used the SETSPN.exe utility
determine that there was more than one SPN for that particular server.
regards,
"Anatoli" wrote:
> Markus,
> Thanks for your reply. From what I can tell, this problem is specific to my
> domain account. That is that I can connect remotely to the SQL server using
> the SA account, but I can't connect using my domain account. I tried using
> another PC from which one of other admins was able to easily connect to
> SQL2005. I don't use a roaming profile, and this was the first time I logged
> onto that PC and still I got the same error. Again, when I logged in locally
> to the SQL server I didn't have any problems SSMS connecting.
> So from what I can tell, there aren't any setting issues on the SQL server
> side nor are there any issues from my PC side as I'm able to connect to other
> instances of SQL 2005 with my domain account.
> Are there any settings associated with the login to cause such an error?
> "MarkusB" wrote:
> > Anatoli,
> >
> > check these links.
> > http://support.microsoft.com/kb/811889/
> >
> > http://msdn2.microsoft.com/en-us/library/ms191153.aspx
> > http://msdn2.microsoft.com/en-us/library/ms189585.aspx
> >
> > Hope this helps
> >
> > Markus
> >
> >